Inhibit all-absent-variant optimization for all enum reprs that inhibit layout optimization, not just repr(C).

This commit is contained in:
Zachary S
2025-09-24 10:22:52 -05:00
parent c8905eaa66
commit 85872cfaa2
3 changed files with 20 additions and 4 deletions
+3 -3
View File
@@ -317,9 +317,9 @@ pub fn layout_of_struct_or_enum<
always_sized: bool,
) -> LayoutCalculatorResult<FieldIdx, VariantIdx, F> {
let (present_first, present_second) = {
let mut present_variants = variants
.iter_enumerated()
.filter_map(|(i, v)| if !repr.c() && absent(v) { None } else { Some(i) });
let mut present_variants = variants.iter_enumerated().filter_map(|(i, v)| {
if !repr.inhibit_enum_layout_opt() && absent(v) { None } else { Some(i) }
});
(present_variants.next(), present_variants.next())
};
let present_first = match present_first {
+10
View File
@@ -22,3 +22,13 @@ enum ScalarPairDifferingSign { //~ERROR: abi: ScalarPair
A(u8),
B(i8),
}
enum Never {}
// See https://github.com/rust-lang/rust/issues/146984
#[rustc_layout(size)]
#[repr(u32)]
enum DefinedLayoutAllUninhabited { //~ERROR: size: Size(4 bytes)
A(Never),
B(Never),
}
+7 -1
View File
@@ -16,5 +16,11 @@ error: abi: ScalarPair(Initialized { value: Int(I8, false), valid_range: 0..=1 }
LL | enum ScalarPairDifferingSign {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors
error: size: Size(4 bytes)
--> $DIR/enum.rs:31:1
|
LL | enum DefinedLayoutAllUninhabited {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 4 previous errors