Skip to content

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

New issue

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

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

Already on GitHub? Sign in to your account

Closed
nham opened this issue Jul 1, 2015 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@nham
Copy link
Contributor

nham commented Jul 1, 2015

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.

@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Jul 1, 2015
@steveklabnik
Copy link
Member

Triage: no change.

@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum
Copy link
Member

I'm not sure how to add notes to lints, but in general I think the changes would need to be done somewhere around here. Perhaps someone could write up some instructions?

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 22, 2017
@GuillaumeGomez
Copy link
Member

Sounds like fun. Doing it.

bors added a commit that referenced this issue Aug 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

4 participants