Skip to content

Spurious "redundant redefinition of a binding" error from redundant_locals #11290

@emarsden

Description

@emarsden

Summary

Nightly clippy is showing what I believe to be a spurious "redundant redefinition of a binding" error for lexically scoped mutable bindings.

Lint Name

redundant_locals

Reproducer

I tried this code:

fn do_shadow_let() {
    let bazzle = 42;
    {
        let bazzle = 69;
        println!("shadow_let: internal bazzle: {bazzle}");
    }
    println!("shadow_let: external bazzle: {bazzle}");
}

fn do_shadow_letmut() {
    let mut bazzle = 0;
    bazzle += 42;
    {
        let mut bazzle = bazzle;
        bazzle = 69;
        println!("shadow_letmut: internal bazzle: {bazzle}");
    }
    println!("shadow_letmut: external bazzle: {bazzle}");
}

fn main () {
    do_shadow_let();
    do_shadow_letmut();
}

I saw this happen:

error: redundant redefinition of a binding
  --> src/main.rs:14:9
   |
14 |     let mut bazzle = 0;
   |         ^^^^^^^^^^
...
17 |         let mut bazzle = bazzle;
   |         ^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: remove the redefinition of `bazzle`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_locals
   = note: `#[deny(clippy::redundant_locals)]` on by default

I expected to see no error for the shadowed mutable binding case, as for the shadowed immutable binding.

Version

rustc 1.73.0-nightly (8131b9774 2023-08-02)
binary: rustc
commit-hash: 8131b9774ebcb6c162fcac71545a13543ec369e7
commit-date: 2023-08-02
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions