Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shadow_unrelated puts entire RHS of shadow var into message #5703

Closed
matthiaskrgr opened this issue Jun 10, 2020 · 1 comment · Fixed by #5788
Closed

shadow_unrelated puts entire RHS of shadow var into message #5703

matthiaskrgr opened this issue Jun 10, 2020 · 1 comment · Fixed by #5788
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy

Comments

@matthiaskrgr
Copy link
Member

#![warn(clippy::shadow_unrelated)]

fn main() {
    let x = true;
    {
        let x = {
            let s = 
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
           println!("{}", s);
            true

            //
            //
            //
            //
            //
            //
            //
            //
        };
    }
}

This generates the warning

warning: `x` is shadowed by `{
            let s =
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
           println!("{}", s);
            true

            //
            //
            //
            //
            //
            //
            //
            //
        }`
  --> src/main.rs:6:13
   |
6  |         let x = {
   |             ^
   |
note: the lint level is defined here
  --> src/main.rs:1:9
   |
1  | #![warn(clippy::shadow_unrelated)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^
note: initialization happens here
  --> src/main.rs:6:17
   |
6  |           let x = {
   |  _________________^
7  | |             let s =
8  | |             "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
9  | |            println!("{}", s);
...  |
19 | |             //
20 | |         };
   | |_________^
note: previous binding is here
  --> src/main.rs:4:9
   |
4  |     let x = true;
   |         ^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#shadow_unrelated

warning: 3 warnings emitted

Not sure what was the idea behind it doing this, but it seems kinda overkill...?

clippy 0.0.212 (feb3536 2020-06-09)

@matthiaskrgr matthiaskrgr added the C-bug Category: Clippy is not doing the correct thing label Jun 10, 2020
@flip1995 flip1995 added the good-first-issue These issues are a good way to get started with Clippy label Jun 12, 2020
@Leulz
Copy link
Contributor

Leulz commented Jul 10, 2020

I'm interested in starting to contribute to this project, can I have this issue assigned to me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants