about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-04-11 19:56:47 +0800
committerGitHub <noreply@github.com>2018-04-11 19:56:47 +0800
commit6eb66fc315065cd92c940d5c1c12d79ebb3d7cd8 (patch)
tree7f71a363edde4fdbe924b307d7d6b0128e518c7d
parentf4b9fdace5a85d14f0ff978ce08cef386d2d7da2 (diff)
parent5edfb53439e7da99a6a382d6507723f99755c7ce (diff)
downloadrust-6eb66fc315065cd92c940d5c1c12d79ebb3d7cd8.tar.gz
rust-6eb66fc315065cd92c940d5c1c12d79ebb3d7cd8.zip
Rollup merge of #49795 - nox:niche-with-uninhabited-fields, r=eddyb
Properly look for uninhabitedness of variants in niche-filling check
-rw-r--r--src/librustc/ty/layout.rs6
-rw-r--r--src/test/run-pass/type-sizes.rs7
2 files changed, 10 insertions, 3 deletions
diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs
index 5f9c305d92f..16d28ff4266 100644
--- a/src/librustc/ty/layout.rs
+++ b/src/librustc/ty/layout.rs
@@ -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);
diff --git a/src/test/run-pass/type-sizes.rs b/src/test/run-pass/type-sizes.rs
index 2f50e63153e..0bb18d8729a 100644
--- a/src/test/run-pass/type-sizes.rs
+++ b/src/test/run-pass/type-sizes.rs
@@ -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 ()>());
 }