Skip to content

Message suggesting prefixing with underscore is unhelpful #66636

Closed

Description

I believe that in the vast majority of cases when an unused variable is present, the author of the code intended to use it, but forgot. Thus the message suggesting to effectively turn off the warning is unhelpful.

I suggest changing it to something like:

help: you probably wanted to use it somehow, check the code around to see if it's the case
help: if you really intend to create the variable and not use it, prefix it with underscore: `_var`

While this doesn't concern me much personally, I believe it'd be much more helpful to novice programmers. To put it in extreme, imagine this kind of lint message: "Reference outlives borrowed value. Consider putting #![allow(undefined_behavior)] at the top of your module."

And I must admit the current warning feels a bit strange to me too. ("Dear compiler, the content of your message is completely useless, but its presence saved my ass twice today, so thank you for that!")

Disclaimer: this is entirely based on my personal experience and may not be true in general. Feel free to close if there's a good evidence that I'm broken, not the compiler. :)

This issue has been assigned to @loris-intergalactique via this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this 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