Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable field reordering for repr(int). #56887

Merged
merged 2 commits into from
Dec 22, 2018

Commits on Dec 16, 2018

  1. Configuration menu
    Copy the full SHA
    fba23d0 View commit details
    Browse the repository at this point in the history
  2. Add test to check order of repr(int) enum fields

    RFC rust-lang#2195 specifies that a repr(int) enum such as:
    
        #[repr(u8)]
        enum MyEnum {
            B { x: u8, y: i16, z: u8 },
        }
    
    has a layout that is equivalent to:
    
        #[repr(C)]
        enum MyEnumVariantB { tag: u8, x: u8, y: i16, z: u8 },
    
    However this isn't actually implemented, with the actual layout being
    roughly equivalent to:
    
        union MyEnumPayload {
            B { x: u8, y: i16, z: u8 },
        }
    
        #[repr(packed)]
        struct MyEnum {
            tag: u8,
            payload: MyEnumPayload,
        }
    
    Thus the variant payload is *not* subject to repr(C) ordering rules, and
    gets re-ordered as `{ x: u8, z: u8, z: i16 }`
    
    The existing tests added in pull-req rust-lang#45688 fail to catch this as the
    repr(C) ordering just happens to match the current Rust ordering in this
    case; adding a third field reveals the problem.
    petertodd authored and emilio committed Dec 16, 2018
    Configuration menu
    Copy the full SHA
    d84bdba View commit details
    Browse the repository at this point in the history