Skip to content

unused import warning should have identifier in first line #37376

Closed
@pnkfelix

Description

@pnkfelix

Currently, the unused_imports lint does not include the identifier that is unused in the first line of its warning output.

Instead, it relies on the span system to highlight the identifier

For example, for the following code:

mod a {
    pub fn foo() { }
    pub fn bar() { }
}

mod b {
    use a::{foo, bar};
}

fn main() {
    a::foo(); a::bar();
}

the produced warning is:

warning: unused import, #[warn(unused_imports)] on by default
 --> <anon>:7:13
  |
7 |     use a::{foo, bar};
  |             ^^^

warning: unused import, #[warn(unused_imports)] on by default
 --> <anon>:7:18
  |
7 |     use a::{foo, bar};
  |                  ^^^

This means that the user who is reviewing the warnings needs to scan down four lines after the warning itself before they can see which identifier is being highlighted. In some contexts, the output may have even flowed off the visible portion of the console output.

Some other similar lints do not suffer from this problem because they include the offending identifier in the first line of the warning. For example, the unused_variables and dead_code lints both include the name of the function or variable in the first line of the warning.

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.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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