Skip to content

#[repr(C)] #[repr(packed)] incorrectly warns about unused attribute #26646

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

Closed
Gankra opened this issue Jun 29, 2015 · 0 comments
Closed

#[repr(C)] #[repr(packed)] incorrectly warns about unused attribute #26646

Gankra opened this issue Jun 29, 2015 · 0 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@Gankra
Copy link
Contributor

Gankra commented Jun 29, 2015

use std::mem::{size_of, align_of};

#[repr(C)] #[repr(packed)] 
struct Foo1(u32, u64);

#[repr(packed)] #[repr(C)] 
struct Foo2(u32, u64);

#[repr(C)] 
struct Foo3(u32, u64);

#[repr(packed)]
struct Foo4(u32, u64);

struct Foo5(u64, u32);


fn main() {
    println!("Foo1 s: {}, a: {}", size_of::<Foo1>(), align_of::<Foo1>());
    println!("Foo2 s: {}, a: {}", size_of::<Foo2>(), align_of::<Foo2>());
    println!("Foo2 s: {}, a: {}", size_of::<Foo3>(), align_of::<Foo3>());
    println!("Foo2 s: {}, a: {}", size_of::<Foo4>(), align_of::<Foo4>());
    println!("Foo2 s: {}, a: {}", size_of::<Foo5>(), align_of::<Foo5>());
}
<anon>:3:12: 3:27 warning: unused attribute, #[warn(unused_attributes)] on by default
<anon>:3 #[repr(C)] #[repr(packed)] 
                    ^~~~~~~~~~~~~~~

Foo1 s: 12, a: 8
Foo2 s: 12, a: 8
Foo2 s: 16, a: 8
Foo2 s: 12, a: 8
Foo2 s: 16, a: 8
@Gankra Gankra added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Jun 29, 2015
bors added a commit that referenced this issue Jun 30, 2015
Fixes #26646.

Loops over all `#[repr(..)]` attributes instead of stopping at the first one to make sure they are all marked as used. Previously it stopped after the first `#[repr(C)]` was found causing all other attributes to be skipped by the linter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

No branches or pull requests

1 participant