-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Name Shadowing #83
Comments
I think shadowing is quite liberally used in Rust, so we should tread lightly here. I think your proposed scheme should work well. I think especially in nested libsyntax code it's quite common to shadow and re-shadow stuff like |
I know that many don't see shadowing as a problem. But I maintain that it does make code harder to visually parse than strictly necessary (where does that Btw. scopes are a good antidote to shadowing – if a binding is out of scope, it cannot shadow anything. Thus, reducing scopes also reduces shadowing. I'd really like to see how many warnings libsyntax would generate with |
Sounds good to me. |
I see you added [T-middle]. Is there something that would ease building this? I figure it would be possible to implement this by walking the AST of any |
I guess an AST walk would work. I was thinking along the lines of |
@Manishearth Now I have a very strange compiler error:
I'm quite sure I have only one definition of each lint. Perhaps a |
This comes from |
Ah, I had registered the lint twice. Thanks, @birkenfeld. |
…ton,alexcrichton
Some people (myself included) think that name shadowing makes code harder to reason about.
Now of course there is a continuum of shadowing operations:
shadow_same
: The name is re-bound to the same data (e.g.let mut x = &mut x;
for mutable re-bind)shadow_reuse_change
: The name is re-used in the bound expression (e.g.let x = x + 1;
)shadow_foreign
: The name is re-bound without even using the original valueWe could create lints for all three groups, plus a
shadow_reuse
lint group that combinesshadow_same
andshadow_reuse_change
and ashadow
lint group that combines all three.Now for those lints, we want to make the macro check more strict in that we do not check within macro expansions at all.
I think (but am open to discussion) that the
shadow_foreign
lint should beWarn
by default, while the others should beAllow
. This won't disturb people too much but still makes for fairly readable code. Organizations or projects can then opt to Deny all shadowing, or whatever suits them.The text was updated successfully, but these errors were encountered: