Skip to content

Display note for "unused variable" warning suggesting that the warning can be disabled via underscores #26720

Closed
@nham

Description

@nham

For reference, see this Reddit thread

It seems to me that if you have code like this

for x in foo {
    // code that does not use `x`...
}

Then in addition to the "unused variable" warning that you currently get:

unused_var.rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variables)] on by default
unused_var.rs:2     for x in [1,2,3].iter() {
                        ^

it should also display a note, perhaps saying

note: to disable this warning, consider using `_x` or `_` instead

Barring that, the lint could have an error code and the error explanation could mention that you can disable the warning in either of these ways.

I'm not sure if this note should only be displayed with for loops (and similar situations), or if it should be unconditionally displayed alongside the "unused variable" warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions