Skip to content

Lint dangerous uses of shadowing #3433

Open
@oli-obk

Description

@oli-obk

We have three shadowing lints

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

#2890

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-guidelinesLint: Related to the Rust API Guidelines

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions