Skip to content
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

used_unused_variable lint #4239

Open
yaahc opened this issue Jun 28, 2019 · 4 comments
Open

used_unused_variable lint #4239

yaahc opened this issue Jun 28, 2019 · 4 comments
Labels
A-lint Area: New lints L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@yaahc
Copy link
Member

yaahc commented Jun 28, 2019

The idea is to lint for variables that have had a _ prepended on them to avoid unused variable lints and then subsequently been used.

The motivation for this change is that I want to use cargo fix --clippy as my default command to run to check my working copy for compiler errors, but it puts _ on the front of variables when I'm initially writing them and then doesn't clean up after itself once I start using said variables. This bothers me and I want to fix it to make my workflow smoother.

We would want to restrict this lint by default, a its entirely reasonable to start variables with an underscore normally, so we don't necessarily want to force people to treat a leading _ as a reserved that they can't use except to indicate a variable is unused.

For this to be useful for my workflow the lint should be marked as MachineApplicable.

@flip1995 flip1995 added L-suggestion Lint: Improving, adding or fixing lint suggestions good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints labels Jun 29, 2019
@yaahc yaahc removed the good-first-issue These issues are a good way to get started with Clippy label Jul 1, 2019
@yaahc
Copy link
Member Author

yaahc commented Jul 1, 2019

The plan here is likely to implement this in rustc rather than as part of clippy, and I believe that is because the infrastructure to do this check already exists in rustc but would have to be reimplemented in clippy.

The one main blocker that I know of is the fact that rustc doesn't have an equivalent for "restricted lints" which are things that are not universally considered bad but that some people may wish to selectively enable. The idea is that we will add this class of lints to rustc and implement used_unused_variable as a restricted rustc lint.

@Manishearth feel free to elaborate on or correct any of the above.

@yaahc
Copy link
Member Author

yaahc commented Jul 1, 2019

I'm going to leave this issue open for now until we've opened an issue against rustc and the compiler folks have agreed to the plan as outlined above.

@flip1995
Copy link
Member

flip1995 commented Jul 2, 2019

rustc doesn't have an equivalent for "restricted lints"

In rustc these would be the allow-by-default lints.

But I think the main problem is, that rustc has the policy to not include new lints, unless they're really necessary (in combination with a new lang feature / edition / ...). I don't think this lint would make it in rustc. For lints like this Clippy exists.

You can "map" lint levels from Clippy to rustc (if a lint would be uplifted) like this:

Clippy rustc
deny-by-default warn-by-default
warn-by-default allow-by-default
allow-by-default not a lint in rustc

Maybe we could expose the rustc interface to Clippy and use this to implement the lint?

@oli-obk
Copy link
Contributor

oli-obk commented Jan 10, 2020

I thought we had such a lint, but it had bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

No branches or pull requests

3 participants