diff options
| author | Erik Desjardins <erikdesjardins@users.noreply.github.com> | 2020-07-16 18:54:26 -0400 |
|---|---|---|
| committer | Erik Desjardins <erikdesjardins@users.noreply.github.com> | 2020-07-17 10:53:02 -0400 |
| commit | 3924672cccb7fb273d197aa2a6f5e130bca96323 (patch) | |
| tree | 003eb5899ca83430278c75096e84bffaa95a1d84 | |
| parent | 2e431c62b6455d8b352b6cd1be69409a31e8de4b (diff) | |
| download | rust-3924672cccb7fb273d197aa2a6f5e130bca96323.tar.gz rust-3924672cccb7fb273d197aa2a6f5e130bca96323.zip | |
document test changes
| -rw-r--r-- | src/test/ui/type-sizes.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/test/ui/type-sizes.rs b/src/test/ui/type-sizes.rs index 0ae9bfcf0bd..73a11a5e743 100644 --- a/src/test/ui/type-sizes.rs +++ b/src/test/ui/type-sizes.rs @@ -103,11 +103,19 @@ enum Option2<A, B> { None } +// Two layouts are considered for `CanBeNicheFilledButShouldnt`: +// Niche-filling: +// { u32 (4 bytes), NonZeroU8 + tag in niche (1 byte), padding (3 bytes) } +// Tagged: +// { tag (1 byte), NonZeroU8 (1 byte), padding (2 bytes), u32 (4 bytes) } +// Both are the same size (due to padding), +// but the tagged layout is better as the tag creates a niche with 254 invalid values, +// allowing types like `Option<Option<CanBeNicheFilledButShouldnt>>` to fit into 8 bytes. pub enum CanBeNicheFilledButShouldnt { A(NonZeroU8, u32), B } -pub enum AlwaysTagged { +pub enum AlwaysTaggedBecauseItHasNoNiche { A(u8, u32), B } @@ -159,7 +167,7 @@ pub fn main() { assert_eq!(size_of::<CanBeNicheFilledButShouldnt>(), 8); assert_eq!(size_of::<Option<CanBeNicheFilledButShouldnt>>(), 8); assert_eq!(size_of::<Option<Option<CanBeNicheFilledButShouldnt>>>(), 8); - assert_eq!(size_of::<AlwaysTagged>(), 8); - assert_eq!(size_of::<Option<AlwaysTagged>>(), 8); - assert_eq!(size_of::<Option<Option<AlwaysTagged>>>(), 8); + assert_eq!(size_of::<AlwaysTaggedBecauseItHasNoNiche>(), 8); + assert_eq!(size_of::<Option<AlwaysTaggedBecauseItHasNoNiche>>(), 8); + assert_eq!(size_of::<Option<Option<AlwaysTaggedBecauseItHasNoNiche>>>(), 8); } |
