-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
A-lintArea: New lintsArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.L-guidelinesLint: Related to the Rust API GuidelinesLint: Related to the Rust API Guidelines
Description
We have three shadowing lints
- shadow reuse
- detect
let x = consuming_operation(x);
- detect
- shadow same
- detect
let x = &x;
- detect
- shadow unrelated
- detect
let x = ...; let x = y;
- detect
which all try to address shadowing issues. Unfortunately enabling either of these lints will also lint idiomatic and readable code. We should find a way to write a lint that only detects actually problematic cases of shadowing.
All of the cases below are even more prominent if you include mutable bindings, as it becomes very hard to distinguish which variable is changed by a x = ...
statement.
Shadowing in a small scope
let x = foo;
....
{
let x = bar;
...
use(x);
use1(x);
}
use2(x); // at this point we see the `use1(x)` above and
// may assume these two `x` are related
Shadowing in match arm patterns
let x = foo;
...
match bar {
Some(x) => use(x),
None => use(x),
}
Shadowing in conditional early aborts
probably not as problematic as the first case mentioned, but would get caught by a naive implementation of the first case.
let x = foo;
....
if meh {
let x = bar;
...
use(x);
use1(x);
return;
}
use2(x); // at this point we see the `use1(x)` above and
// may assume these two `x` are related
phansch, marcospb19, jayaddison, kvark, KutnerUri and 1 more
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.L-guidelinesLint: Related to the Rust API GuidelinesLint: Related to the Rust API Guidelines