Skip to content

Commit b37f571

Browse files
committed
updated the comment to formally justify that align([T]) == align(T)
1 parent 585af05 commit b37f571

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

compiler/rustc_const_eval/src/util/alignment.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ where
4646
}
4747
}
4848
Err(_) => {
49-
// Soundness-critical: this may return false positives (reporting potential misalignment),
50-
// but must not return false negatives. When layout is unavailable, we stay conservative
51-
// except for arrays of u8/i8 whose ABI alignment is provably 1.
49+
// Soundness: For any `T`, the ABI alignment requirement of `[T]` equals that of `T`.
50+
// Proof sketch:
51+
// (1) From `&[T]` we can obtain `&T`, hence align([T]) >= align(T).
52+
// (2) Using `std::array::from_ref(&T)` we can obtain `&[T; 1]` (and thus `&[T]`),
53+
// hence align(T) >= align([T]).
54+
// Therefore align([T]) == align(T). Length does not affect alignment.
5255

5356
// Try to determine alignment from the type structure
5457
if let Some(element_align) = get_element_alignment(tcx, ty) {

0 commit comments

Comments
 (0)