Comments (8)
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 ty
and expr
because they end up being used a lot. But those users can just disable the lint.
from rust-clippy.
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 foo
come from again?). And often, reusing a binding stems from lazyness to think up a more specific name.
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 shadow_foreign
turned on. 😄
from rust-clippy.
Sounds good to me.
from rust-clippy.
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 fn
and keeping a chain of sets of local bindings (one for each scope), but perhaps there is an easier solution?
from rust-clippy.
I guess an AST walk would work. I was thinking along the lines of ExprUseVisitor
but that's not exactly what we want anyway.
from rust-clippy.
@Manishearth Now I have a very strange compiler error:
error: duplicate specification of lint shadow_same
error: duplicate specification of lint shadow_reuse
error: duplicate specification of lint shadow_foreign
I'm quite sure I have only one definition of each lint. Perhaps a rustup --channel=nightly
will fix it.
from rust-clippy.
This comes from get_lints()
returning the same lint name(s) for multiple passes.
from rust-clippy.
Ah, I had registered the lint twice. Thanks, @birkenfeld.
from rust-clippy.
Related Issues (20)
- Don't fire items_after_statements when the statement isn't used before its declaration
- `clippy::suspicious_operation_groupings` creates code that fails to compile HOT 1
- `range_plus_one` also triggers if both sides have a plus one
- new lint: pointer created from transmuting an int into a pointer is not able to be dereferenced HOT 3
- lint on `OR | PATTERN if call()` HOT 4
- Documentation for from_iter_instead_of_collect is incorrect
- Suggestion of `.copied()` with `.skip_while()` doesn't compile HOT 3
- `needless_pass_by_value`: Wrongly emit on Rc values HOT 2
- MSRV-aware `std_instead_of_core` HOT 1
- Incorrect clippy::derivable_impls in the presence of conditional compilation
- `manual_unwrap_or_default` generates invalid code for nested pattern match HOT 2
- needless_borrows_for_generic_args on large array HOT 5
- [Project Goal, Help Wanted] Optimizing MSRV attribute collection HOT 2
- needless_borrows_for_generic_arg fires incorrectly on &mut variable inside closure HOT 3
- False `almost_complete_letter_range` when the endpoint is matched separately HOT 1
- `needless_pass_by_ref_mut` should not trigger when values derived from the `&mut` are used in an unsafe block HOT 1
- `doc_markdown` footnote identifier false positive
- `explicit_iter_loop` false positive on `&Box<[_]>` with MSRV < 1.80
- `manual_inspect` suggestion breaks mutating code
- `wildcard_imports` is ignored in test crates HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-clippy.