-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
lint against using a binding whose name is prefixed with an underscore #488
Comments
I like this idea, but I don't know how to do it without duplicating liveness. Perhaps exprusevisitor. |
Maybe there's another way. Look for |
I'm an idiot. Thanks. |
glad I'm not alone ;) |
Welcome to the club. 😜 |
I could do this if someone is willing to mentor. |
@devonhollowood I'll try. What do you need? I'm reachable on irc if you need real-time-feedback For variables you probably just need an |
Or a local variable. You can do these checks with the |
do we need the definition? Maybe for ensuring that the error is only reported once? |
No, for ensuring that it is indeed a variable, not a function or something 😄 |
Okay so I'm finally getting a chance to dig into this (work suddenly got very busy over the past couple days). I'm a little confused by the discussion here--is my understanding (below) correct?
|
Well, more like:
ExprTupField and ExprIndex don't have paths that can start with an underscore the rest is correct. |
Here's what I've got so far. This seems to pick up a lot of false positives though, so I must be doing something wrong. For example, it lints all of the following:
I think the |
This could certainly use a macro check. Look at utils::in_macro |
Okay, so I think you were right @llogiq in that the issue was in the macros themselves. I tried printing out the matched
because that is using an underscore-prefixed variable. So how would one check that that the definition of |
Well, just check that the ident for (might not work, not sure how the new hygiene stuff works) |
@Manishearth I went ahead and added that, but it doesn't seem to work as expected. For example, it will still lint this:
(it's matching the |
I'm thinking it might make sense to not lint in the case of >1 leading underscore, since I think that has a different traditional meaning than a single leading underscore. I tried out only linting for cases with exactly one leading underscore, and it seems to fix the built-in macros problem. If you're okay with that solution, I'll run dogfood, clean up any offending code code and submit the pull request. |
Usually used to mark private things which are public due to unavoidable reasons, but not always the case. |
I don't understand why this lint was added. What am I supposed to use instead for lock guards that I don't call any methods on or pass around? The wiki doesn't mention this new lint, only the README does. |
This doesn't affect that? This is when you use a variable tagged An unused lock guard is fine. If it didn't have the underscore, it would have triggered (We don't immediately update the wiki) |
The errors are indeed not for the guard code I've written (my bad), but the code generated by |
(fixed, needed an external macro check) |
The lint still gets triggered on |
Early lints passes are pre desugaring, but macros are still expanded. We could add another "veryearlylintpass" to the compiler for pre-expansion since the ast is the same. |
OK, that probably makes sense. Otherwise, we could create a check to see if some span originates from the macro expansion or the expanded code (if that is somehow possible). |
As far as I can see, this lint has been updated a few times since the last comments. In particular, it now has tests that make sure that code generated by macros is not linted. In |
Shouldn't this issue be closed? Is there something else to handle related directly to this issue? |
Yeah, we should close this with a separate issue opened about making this non-pedantic if people care about that. |
Prefixing an underscore to a binding is done to silence
unused
warnings. This makes it easy to recognize explicitly unused bindings by their name, and still have a name that tells you something about the binding. In case you start using the binding, you should remove the underscore.The text was updated successfully, but these errors were encountered: