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

std::repr does not work properly for packed fields #13486

Closed
stepancheg opened this issue Apr 12, 2014 · 3 comments
Closed

std::repr does not work properly for packed fields #13486

stepancheg opened this issue Apr 12, 2014 · 3 comments

Comments

@stepancheg
Copy link
Contributor

Problem with std::repr (and with std::reflect) is that TyVisitor does not tell whether struct is packed or not.

I think, proper solution would be adding offset parameter to fn visit_class_field(...) callback, to remove all complex offsets/alignment computation code from libstd (because it is already done in librustc).

@emberian
Copy link
Member

eugh what a pain. I thought reflect was already doing this.

@KokaKiwi
Copy link

KokaKiwi commented May 9, 2014

Just a comment to give a code example of the issue (which doesn't appears to have been fixed):

#[packed]
struct Packed {
    a: u8,
    b: u32,
    c: [u8, ..3],
}

struct NonPacked {
    a: u8,
    b: u32,
    c: [u8, ..3],
}

fn main() {
    let p = Packed {
        a: 1,
        b: 3,
        c: [3, 4, 5],
    };

    println!("{:?}", p);

    let p = NonPacked {
        a: 1,
        b: 3,
        c: [3, 4, 5],
    };

    println!("{:?}", p);
}

Output:

$ rustc -o packed main.rs
$ ./packed
Packed{a: 1u8, b: 84148992u32, c: [243u8, 144u8, 68u8]}
NonPacked{a: 1u8, b: 3u32, c: [3u8, 4u8, 5u8]}

My rustc version:

$ rustc --version
rustc 0.11-pre-nightly (2dcbad5 2014-05-06 22:01:43 -0700)
host: x86_64-unknown-linux-gnu

@thestinger
Copy link
Contributor

Reflection has been removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants