Skip to content

Commit

Permalink
Rollup merge of rust-lang#49795 - nox:niche-with-uninhabited-fields, …
Browse files Browse the repository at this point in the history
…r=eddyb

Properly look for uninhabitedness of variants in niche-filling check
  • Loading branch information
kennytm authored Apr 11, 2018
2 parents f4b9fda + 5edfb53 commit 6eb66fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1471,10 +1471,10 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {

// Find one non-ZST variant.
'variants: for (v, fields) in variants.iter().enumerate() {
if fields.iter().any(|f| f.abi == Abi::Uninhabited) {
continue 'variants;
}
for f in fields {
if f.abi == Abi::Uninhabited {
continue 'variants;
}
if !f.is_zst() {
if dataful_variant.is_none() {
dataful_variant = Some(v);
Expand Down
7 changes: 7 additions & 0 deletions src/test/run-pass/type-sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ enum ReorderedEnum {
B(u8, u16, u8),
}

enum NicheFilledEnumWithInhabitedVariant {
A(&'static ()),
B(&'static (), !),
C,
}

pub fn main() {
assert_eq!(size_of::<u8>(), 1 as usize);
assert_eq!(size_of::<u32>(), 4 as usize);
Expand All @@ -67,4 +73,5 @@ pub fn main() {
assert_eq!(size_of::<e3>(), 4 as usize);
assert_eq!(size_of::<ReorderedStruct>(), 4);
assert_eq!(size_of::<ReorderedEnum>(), 6);
assert_eq!(size_of::<NicheFilledEnumWithInhabitedVariant>(), size_of::<&'static ()>());
}

0 comments on commit 6eb66fc

Please sign in to comment.