Skip to content

dead_code lint highlights too much on functions with multi-line signatures #63064

Closed
@alvinhochun

Description

@alvinhochun

With the following example code:

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

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

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

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

(Playground)

The compiler produces these warnings:

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

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

warning: function is never used: `unused3`
  --> src/main.rs:9:1
   |
9  | / fn unused3(
10 | |     var: i32,
11 | | ) {
12 | |     println!("bar {}", var);
13 | | }
   | |_^

Notice that for fn unused and fn unused2, dead_code is reported on only the first line signature of the function, however for fn unused3 dead_code is reported on the whole function from start to finish.

This is mostly annoying when writing new functions in an editor like vscode that rls will cause the whole function to be orange-wavy-underlined, making a huge distraction.

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-bugCategory: This is a bug.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

    No branches or pull requests

    Issue actions