Skip to content

Commit 6eb66fc

Browse files
authored
Rollup merge of rust-lang#49795 - nox:niche-with-uninhabited-fields, r=eddyb
Properly look for uninhabitedness of variants in niche-filling check
2 parents f4b9fda + 5edfb53 commit 6eb66fc

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/librustc/ty/layout.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1471,10 +1471,10 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
14711471

14721472
// Find one non-ZST variant.
14731473
'variants: for (v, fields) in variants.iter().enumerate() {
1474+
if fields.iter().any(|f| f.abi == Abi::Uninhabited) {
1475+
continue 'variants;
1476+
}
14741477
for f in fields {
1475-
if f.abi == Abi::Uninhabited {
1476-
continue 'variants;
1477-
}
14781478
if !f.is_zst() {
14791479
if dataful_variant.is_none() {
14801480
dataful_variant = Some(v);

src/test/run-pass/type-sizes.rs

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ enum ReorderedEnum {
4242
B(u8, u16, u8),
4343
}
4444

45+
enum NicheFilledEnumWithInhabitedVariant {
46+
A(&'static ()),
47+
B(&'static (), !),
48+
C,
49+
}
50+
4551
pub fn main() {
4652
assert_eq!(size_of::<u8>(), 1 as usize);
4753
assert_eq!(size_of::<u32>(), 4 as usize);
@@ -67,4 +73,5 @@ pub fn main() {
6773
assert_eq!(size_of::<e3>(), 4 as usize);
6874
assert_eq!(size_of::<ReorderedStruct>(), 4);
6975
assert_eq!(size_of::<ReorderedEnum>(), 6);
76+
assert_eq!(size_of::<NicheFilledEnumWithInhabitedVariant>(), size_of::<&'static ()>());
7077
}

0 commit comments

Comments
 (0)