Skip to content

Commit 0ce0251

Browse files
committed
uses_power_alignment: wording tweaks
1 parent e77a8f4 commit 0ce0251

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

compiler/rustc_lint/src/types.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -756,10 +756,10 @@ declare_lint! {
756756
/// *subsequent* fields of the associated structs to use an alignment value
757757
/// where the floating-point type is aligned on a 4-byte boundary.
758758
///
759-
/// The power alignment rule for structs needed for C compatibility is
760-
/// unimplementable within `repr(C)` in the compiler without building in
761-
/// handling of references to packed fields and infectious nested layouts,
762-
/// so a warning is produced in these situations.
759+
/// Effectively, subsequent floating-point fields act as-if they are `repr(packed(4))`. This
760+
/// would be unsound to do in a `repr(C)` type without all the restrictions that come with
761+
/// `repr(packed)`. Rust instead chooses a layout that maintains soundness of Rust code, at the
762+
/// expense of incompatibility with C code.
763763
///
764764
/// ### Example
765765
///
@@ -791,8 +791,10 @@ declare_lint! {
791791
/// - offset_of!(Floats, a) == 0
792792
/// - offset_of!(Floats, b) == 8
793793
/// - offset_of!(Floats, c) == 12
794-
/// However, rust currently aligns `c` at offset_of!(Floats, c) == 16.
795-
/// Thus, a warning should be produced for the above struct in this case.
794+
///
795+
/// However, Rust currently aligns `c` at `offset_of!(Floats, c) == 16`.
796+
/// Using offset 12 would be unsound since `f64` generally must be 8-aligned on this target.
797+
/// Thus, a warning is produced for the above struct.
796798
USES_POWER_ALIGNMENT,
797799
Warn,
798800
"Structs do not follow the power alignment rule under repr(C)"

0 commit comments

Comments
 (0)