Skip to content

dead_code warnings are wrong #18618

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
mahkoh opened this issue Nov 4, 2014 · 6 comments
Closed

dead_code warnings are wrong #18618

mahkoh opened this issue Nov 4, 2014 · 6 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@mahkoh
Copy link
Contributor

mahkoh commented Nov 4, 2014

In some cases, removing this dead code will cause an error.

@sfackler
Copy link
Member

sfackler commented Nov 4, 2014

Do you have an example?

@mahkoh
Copy link
Contributor Author

mahkoh commented Nov 4, 2014

static A: u8 = 1;
fn f() { A; }
fn main() { }
test5.rs:1:1: 1:18 warning: static item is never used: `A`, #[warn(dead_code)] on by default
test5.rs:1 static A: u8 = 1;
           ^~~~~~~~~~~~~~~~~

@steveklabnik
Copy link
Member

A is never used in that case, though.

@mahkoh
Copy link
Contributor Author

mahkoh commented Nov 4, 2014

test5.rs:1:10: 1:11 error: unresolved name `A`.
test5.rs:1 fn f() { A; }
                    ^

@sfackler
Copy link
Member

sfackler commented Nov 4, 2014

The dead code warning is transitive by design:

fn foo() {}

fn bar() {
    foo()
}

fn main() {}
<anon>:1:1: 1:12 warning: function is never used: `foo`, #[warn(dead_code)] on by default
<anon>:1 fn foo() {}
         ^~~~~~~~~~~
<anon>:3:1: 5:2 warning: function is never used: `bar`, #[warn(dead_code)] on by default
<anon>:3 fn bar() {
<anon>:4     foo()
<anon>:5 }

@ghost
Copy link

ghost commented Nov 4, 2014

There are two desired properties of the dead code lint that it would ideally exhibit:

  1. Removing any subset of items classified as unused from a well-formed program always leaves the resulting program in a compiling state.
  2. Removing any item classified as unused never introduces new "unused code" warnings.

Unfortunately, it is impossible to satisfy both so we're choosing 2) over 1). I'm not sure it's the right choice.

@ghost ghost self-assigned this Dec 12, 2014
@sanxiyn sanxiyn added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Jan 25, 2015
@mahkoh mahkoh closed this as completed Apr 11, 2015
@rust-lang rust-lang locked and limited conversation to collaborators Apr 11, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

No branches or pull requests

4 participants