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

dead_code lint false positive #45614

Closed
leonardo-m opened this issue Oct 29, 2017 · 3 comments
Closed

dead_code lint false positive #45614

leonardo-m opened this issue Oct 29, 2017 · 3 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.

Comments

@leonardo-m
Copy link

fn main() {
    struct Foo<T> { x: T }
    type Bar = Foo<u32>;
    let spam = |Bar { x }| x != 0;
    println!("{}", spam(Foo { x: 10 }));
}

Gives:

warning: type alias is never used: `Bar`
 --> ...\test.rs:3:5
  |
3 |     type Bar = Foo<u32>;
  |     ^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default
@kennytm kennytm added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. labels Oct 29, 2017
@sinkuu
Copy link
Contributor

sinkuu commented Oct 29, 2017

Minimized:

fn main() {
    struct Foo{} // warning: struct is never used
    let _ = |Foo{}| ();
}

So dead_code lint ignores type paths mentioned in patterns (2ec795b).

@scottmcm
Copy link
Member

Repro without closure:

fn main() {
    struct Foo{} // warning: struct is never used
    let Foo{} = return;
}

@petrochenkov
Copy link
Contributor

petrochenkov commented Oct 30, 2017

Code in #45614 (comment) and #45614 (comment) looks pretty dead. At least the structure can be considered dead if it is never constructed.

The original example in #45614 (comment) is different - the structure is constructed there and only liveness of the type alias Bar is misinterpreted, not of the structure itself.
Alias should be considered used whenever it's named, not necessarily constructed.

kennytm added a commit to kennytm/rust that referenced this issue Nov 1, 2017
…ielb1

Count type aliases used in patterns as usage by dead_code lint

Fixes rust-lang#45614.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint 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

5 participants