File tree Expand file tree Collapse file tree 1 file changed +2
-19
lines changed
compiler/rustc_const_eval/src/util Expand file tree Collapse file tree 1 file changed +2
-19
lines changed Original file line number Diff line number Diff line change 6464 }
6565}
6666
67- /// Returns the ABI alignment of the *element type* if `ty` is an array/slice,
68- /// otherwise `None`.
69- ///
70- /// Soundness note:
71- /// For any `T`, the ABI alignment of `[T]` (and `[T; N]`) equals that of `T`
72- /// and does not depend on the length `N`.
73- /// Proof sketch:
74- /// (1) From `&[T]` we can obtain `&T` ⇒ align([T]) ≥ align(T).
75- /// (2) From `&T` we can obtain `&[T; 1]` via `std::array::from_ref`
76- /// (and thus `&[T]`) ⇒ align(T) ≥ align([T]).
77- /// Hence `align([T]) == align(T)`.
78- ///
79- /// Therefore, when `layout_of([T; N])` is unavailable in generic contexts,
80- /// it is sufficient (and safe) to use `layout_of(T)` for alignment checks.
81- ///
82- /// Returns:
83- /// - `Some(align)` if `ty` is `Array(elem, _)` or `Slice(elem)` and
84- /// `layout_of(elem)` is available;
85- /// - `None` otherwise (caller should stay conservative).
67+ // For arrays/slices, `align([T]) == align(T)` (independent of length).
68+ // So if layout_of([T; N]) is unavailable, we can fall back to layout_of(T).
8669fn get_element_alignment < ' tcx > (
8770 tcx : TyCtxt < ' tcx > ,
8871 typing_env : ty:: TypingEnv < ' tcx > ,
You can’t perform that action at this time.
0 commit comments