1
Fork 0

Rollup merge of #49795 - nox:niche-with-uninhabited-fields, r=eddyb

Properly look for uninhabitedness of variants in niche-filling check
This commit is contained in:
kennytm 2018-04-11 19:56:47 +08:00 committed by GitHub
commit 6eb66fc315
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -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() {
for f in fields {
if f.abi == Abi::Uninhabited {
if fields.iter().any(|f| f.abi == Abi::Uninhabited) {
continue 'variants;
}
for f in fields {
if !f.is_zst() {
if dataful_variant.is_none() {
dataful_variant = Some(v);

View file

@ -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);
@ -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 ()>());
}