Skip to content

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

@alvinhochun

Description

@alvinhochun

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)

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Nov 22, 2019
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[/+] on Nov 22, 2019
added a commit that references this issue on May 9, 2020
966589e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @jonas-schievink@alvinhochun

      Issue actions

        dead_code lint highlights more than the ident for impl function · Issue #66627 · rust-lang/rust