Skip to content

dead_code lint highlights more than the ident for impl function #66627

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
alvinhochun opened this issue Nov 22, 2019 · 0 comments · Fixed by #71947
Closed

dead_code lint highlights more than the ident for impl function #66627

alvinhochun opened this issue Nov 22, 2019 · 0 comments · Fixed by #71947
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alvinhochun
Copy link

alvinhochun commented Nov 22, 2019

This is a follow-up of #58729 and #63064. PR #65830 fixed the issue of too much being highlighted for plain functions, but it appears to not apply to impl functions.

With the following example code:

fn unused() {
    println!("blah");
}

fn unused2(var: i32) {
    println!("foo {}", var);
}

fn unused3(
    var: i32,
) {
    println!("bar {}", var);
}

struct UnusedStruct {
    
}

impl UnusedStruct {
    fn unused_impl_fn_1() {
        println!("blah");
    }

    fn unused_impl_fn_2(var: i32) {
        println!("foo {}", var);
    }

    fn unused_impl_fn_3(
        var: i32,
    ) {
        println!("bar {}", var);
    }
}

fn main() {
    println!("Hello world!");
}

(Playground)

The compiler produces these warnings (on 1.41.0-nightly 2019-11-21 53712f8):

warning: function is never used: `unused`
 --> src/main.rs:1:4
  |
1 | fn unused() {
  |    ^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: function is never used: `unused2`
 --> src/main.rs:5:4
  |
5 | fn unused2(var: i32) {
  |    ^^^^^^^

warning: function is never used: `unused3`
 --> src/main.rs:9:4
  |
9 | fn unused3(
  |    ^^^^^^^

warning: struct is never constructed: `UnusedStruct`
  --> src/main.rs:15:8
   |
15 | struct UnusedStruct {
   |        ^^^^^^^^^^^^

warning: method is never used: `unused_impl_fn_1`
  --> src/main.rs:20:5
   |
20 |     fn unused_impl_fn_1() {
   |     ^^^^^^^^^^^^^^^^^^^^^

warning: method is never used: `unused_impl_fn_2`
  --> src/main.rs:24:5
   |
24 |     fn unused_impl_fn_2(var: i32) {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: method is never used: `unused_impl_fn_3`
  --> src/main.rs:28:5
   |
28 | /     fn unused_impl_fn_3(
29 | |         var: i32,
30 | |     ) {
31 | |         println!("bar {}", var);
32 | |     }
   | |_____^

This verifies that the aforementioned fix is working for unused1/unused2/unused3, but not for unused_impl_fn_1/unused_impl_fn_2/unused_impl_fn_3.

(pinging @Quantumplation, @estebank)

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 22, 2019
@alvinhochun alvinhochun changed the title dead_code lint highlights more than the ident for trait impl function dead_code lint highlights more than the ident for impl function Nov 22, 2019
@bors bors closed this as completed in 966589e May 9, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants