Closed
Description
#![allow(dead_code)]
use std::collections::HashSet;
use std::mem::size_of;
struct InlineData {
size: u8,
data: [u32; 13],
}
enum DataA {
Inline(InlineData),
Heap(HashSet<u32>),
}
enum DataB {
Inline {
size: u8,
data: [u32; 13],
},
Heap(HashSet<u32>),
}
fn main() {
assert_eq!(size_of::<DataA>(), size_of::<DataB>());
}
Output:
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `64`,
right: `56`', src/main.rs:25:3
I'd expect DataA and DataB to have the same size. I certainly wouldn't expect a simple refactoring that extracts an inline struct into a named one to increase the size of the enum.
My guess as to what's happening here is that rustc isn't smart enough to put the enum discriminant into the InlineData
padding bytes.
cc @jwilm
Metadata
Metadata
Assignees
Labels
No labels