Skip to content

shadow_unrelated breaks when intermediary bindings are used #3200

@gnzlbg

Description

@gnzlbg

Playground:

pub fn foo(a: i32) {
    let b = 3 * (3 + 1) / 2;
    let c = (f64::from(a) / f64::from(b)) as i32;

    let a = c + b;

    let _ = a;
}

produces

error: `a` is shadowed by `c + b`
 --> src/main.rs:8:9
  |
8 |     let a = c + b;
  |         ^
  |
note: lint level defined here
 --> src/main.rs:2:44
  |
2 | #![cfg_attr(feature = "cargo-clippy", deny(clippy::shadow_unrelated))]
  |                                            ^^^^^^^^^^^^^^^^^^^^^^^^
note: initialization happens here
 --> src/main.rs:8:13
  |
8 |     let a = c + b;
  |             ^^^^^
note: previous binding is here
 --> src/main.rs:4:12
  |
4 | pub fn foo(a: i32) {

The lint incorrectly errors that the new binding a is unrelated to the function argument a, but this is incorrect since these two bindings are related via c.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions