about summary refs log tree commit diff
path: root/tests/ui
diff options
context:
space:
mode:
authorAdwin White <adwinw01@gmail.com>2024-09-18 17:30:27 +0800
committerAdwin White <adwinw01@gmail.com>2024-09-18 17:31:56 +0800
commit9ac23dde37efc573ef57efa92bdf63c2f05846a9 (patch)
treed6fccbfc06827dc6e0d2c81c857c418c19cb48e7 /tests/ui
parentf6bcd094abe174a218f7cf406e75521be4199f88 (diff)
downloadrust-9ac23dde37efc573ef57efa92bdf63c2f05846a9.tar.gz
rust-9ac23dde37efc573ef57efa92bdf63c2f05846a9.zip
Get rid of niche selection's dependence on fields's order
Diffstat (limited to 'tests/ui')
-rw-r--r--tests/ui/structs-enums/type-sizes.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/ui/structs-enums/type-sizes.rs b/tests/ui/structs-enums/type-sizes.rs
index 5ca9c8678b7..f49ce33841a 100644
--- a/tests/ui/structs-enums/type-sizes.rs
+++ b/tests/ui/structs-enums/type-sizes.rs
@@ -209,6 +209,23 @@ struct ReorderEndNiche {
     b: MiddleNiche4,
 }
 
+// We want that the niche selection doesn't depend on order of the fields. See issue #125630.
+pub enum NicheFieldOrder1 {
+    A {
+        x: NonZero<u64>,
+        y: [NonZero<u64>; 2],
+    },
+    B([u64; 2]),
+}
+
+pub enum NicheFieldOrder2 {
+    A {
+        y: [NonZero<u64>; 2],
+        x: NonZero<u64>,
+    },
+    B([u64; 2]),
+}
+
 
 // standins for std types which we want to be laid out in a reasonable way
 struct RawVecDummy {
@@ -260,6 +277,9 @@ pub fn main() {
                size_of::<EnumWithMaybeUninhabitedVariant<()>>());
     assert_eq!(size_of::<NicheFilledEnumWithAbsentVariant>(), size_of::<&'static ()>());
 
+    assert_eq!(size_of::<NicheFieldOrder1>(), 24);
+    assert_eq!(size_of::<NicheFieldOrder2>(), 24);
+
     assert_eq!(size_of::<Option<Option<(bool, &())>>>(), size_of::<(bool, &())>());
     assert_eq!(size_of::<Option<Option<(&(), bool)>>>(), size_of::<(bool, &())>());
     assert_eq!(size_of::<Option<Option2<bool, &()>>>(), size_of::<(bool, &())>());