Can the Rust compiler flatten inner structs and reorder all fields?

52 points SaltyMaybe7887 32 comments
struct Inner {
    a: u32,
    b: u8,
}

struct Outer {
    c: u16,
    inner: Inner,
    d: u8,
}

Is the Rust compiler allowed to make the outer struct have the following memory layout?

struct Outer {
    a: u32,
    c: u16,
    b: u8,
    d: u8,
}

If it isn't, why?