You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of #147185 - RalfJung:repr-c-not-zst, r=petrochenkov
repr(transparent): do not consider repr(C) types to be 1-ZST
Context: rust-lang/unsafe-code-guidelines#552
This experiments with a [suggestion](rust-lang/rfcs#3845 (comment)) by ```@RustyYato``` to stop considering repr(C) types as 1-ZST for the purpose of repr(transparent). If we go with rust-lang/rfcs#3845 (or another approach for fixing repr(C)), they will anyway not be ZST on all targets any more, so this removes a portability hazard. Furthermore, zero-sized repr(C) structs [may have to be treated](rust-lang/unsafe-code-guidelines#552 (comment)) as non-ZST for the win64 ABI (at least that's what gcc/clang do), so allowing them to be ignored in repr(transparent) types is not entirely coherent.
Turns out we already have an FCW for repr(transparent), namely #78586. This extends that lint to also check for repr(C).
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3044
3048
/// = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
3045
-
/// = note: this struct contains `NonExhaustiveZst`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
3049
+
/// = note: this field contains `NonExhaustiveZst`, which is marked with `#[non_exhaustive]`, so it could become non-zero-sized in the future.
3050
+
///
3051
+
/// error: zero-sized fields in repr(transparent) cannot contain `#[repr(C)]` types
3052
+
/// --> src/main.rs:5:28
3053
+
/// |
3054
+
/// 5 | struct Baz(u32, CZst);
3055
+
/// | ^^^^
3056
+
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3057
+
/// = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
3058
+
/// = note: this field contains `CZst`, which is a `#[repr(C)]` type, so it is not guaranteed to be zero-sized on all targets.
0 commit comments