Skip to content

False-positive "field is never used" warning with unions #43393

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
kennytm opened this issue Jul 21, 2017 · 1 comment
Closed

False-positive "field is never used" warning with unions #43393

kennytm opened this issue Jul 21, 2017 · 1 comment
Assignees
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.

Comments

@kennytm
Copy link
Member

kennytm commented Jul 21, 2017

(This has already been reported in #32836 (comment) but not as a proper issue, and I still encountered this today, so filed a separated issue here to ensure it is still visible.)

Test case:

union U {
    x: u32,
    y: f32,
}
fn main() {
    let u = U { x: 0x3f800000 };
    let _f = unsafe { u.y };
}

This produces an unused field warning, which is incorrect:

warning: field is never used: `x`
 --> src/main.rs:2:5
  |
2 |     x: u32,
  |     ^^^^^^
  |
  = note: #[warn(dead_code)] on by default

The initialization of field x should also be considered a use.


Repro on playground, all of stable (1.19.0), beta (1.20.0-beta.1) and nightly (1.20.0-nightly ae98ebf 2017-07-20).

@GuillaumeGomez
Copy link
Member

Taking a look.

@GuillaumeGomez GuillaumeGomez self-assigned this Jul 21, 2017
@Mark-Simulacrum Mark-Simulacrum added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. labels Jul 26, 2017
bors added a commit that referenced this issue Aug 6, 2017
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. C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants