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.

flip1995 pushed a commit to flip1995/rust that referenced this issue Oct 10, 2024
Don't warn on proc macro generated code in `needless_return`

Fixes rust-lang#13458
Fixes rust-lang#13457
Fixes rust-lang#13467
Fixes rust-lang#13479
Fixes rust-lang#13481
Fixes rust-lang#13526
Fixes rust-lang#13486

The fix is unfortunately a little more convoluted than just simply adding a `is_from_proc_macro`. That check *does*  fix the issue, however it also introduces a bunch of false negatives in the tests, specifically when the returned expression is in a different syntax context, e.g. `return format!(..)`.

The proc macro check builds up a start and end pattern based on the HIR nodes and compares it to a snippet of the span, however that would currently fail for `return format!(..)` because we would have the patterns `("return", <something inside of the format macro>)`, which doesn't compare equal. So we now return an empty string pattern for when it's in a different syntax context.

"Hide whitespace" helps a bit for reviewing the proc macro detection change

changelog: none
rust-cloud-vms bot pushed a commit to liwagu/rust that referenced this issue Oct 10, 2024
Don't warn on proc macro generated code in `needless_return`

Fixes rust-lang#13458
Fixes rust-lang#13457
Fixes rust-lang#13467
Fixes rust-lang#13479
Fixes rust-lang#13481
Fixes rust-lang#13526
Fixes rust-lang#13486

The fix is unfortunately a little more convoluted than just simply adding a `is_from_proc_macro`. That check *does*  fix the issue, however it also introduces a bunch of false negatives in the tests, specifically when the returned expression is in a different syntax context, e.g. `return format!(..)`.

The proc macro check builds up a start and end pattern based on the HIR nodes and compares it to a snippet of the span, however that would currently fail for `return format!(..)` because we would have the patterns `("return", <something inside of the format macro>)`, which doesn't compare equal. So we now return an empty string pattern for when it's in a different syntax context.

"Hide whitespace" helps a bit for reviewing the proc macro detection change

changelog: none
flip1995 pushed a commit to flip1995/rust that referenced this issue Oct 18, 2024
Don't warn on proc macro generated code in `needless_return`

Fixes rust-lang#13458
Fixes rust-lang#13457
Fixes rust-lang#13467
Fixes rust-lang#13479
Fixes rust-lang#13481
Fixes rust-lang#13526
Fixes rust-lang#13486

The fix is unfortunately a little more convoluted than just simply adding a `is_from_proc_macro`. That check *does*  fix the issue, however it also introduces a bunch of false negatives in the tests, specifically when the returned expression is in a different syntax context, e.g. `return format!(..)`.

The proc macro check builds up a start and end pattern based on the HIR nodes and compares it to a snippet of the span, however that would currently fail for `return format!(..)` because we would have the patterns `("return", <something inside of the format macro>)`, which doesn't compare equal. So we now return an empty string pattern for when it's in a different syntax context.

"Hide whitespace" helps a bit for reviewing the proc macro detection change

changelog: none
flip1995 pushed a commit to flip1995/rust that referenced this issue Oct 18, 2024
Don't warn on proc macro generated code in `needless_return`

Fixes rust-lang#13458
Fixes rust-lang#13457
Fixes rust-lang#13467
Fixes rust-lang#13479
Fixes rust-lang#13481
Fixes rust-lang#13526
Fixes rust-lang#13486

The fix is unfortunately a little more convoluted than just simply adding a `is_from_proc_macro`. That check *does*  fix the issue, however it also introduces a bunch of false negatives in the tests, specifically when the returned expression is in a different syntax context, e.g. `return format!(..)`.

The proc macro check builds up a start and end pattern based on the HIR nodes and compares it to a snippet of the span, however that would currently fail for `return format!(..)` because we would have the patterns `("return", <something inside of the format macro>)`, which doesn't compare equal. So we now return an empty string pattern for when it's in a different syntax context.

"Hide whitespace" helps a bit for reviewing the proc macro detection change

changelog: none
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