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

False positive "variable does not need to be mutable" with two closures #59620

Closed
Riateche opened this issue Apr 1, 2019 · 0 comments · Fixed by #59708
Closed

False positive "variable does not need to be mutable" with two closures #59620

Riateche opened this issue Apr 1, 2019 · 0 comments · Fixed by #59708
Assignees
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-NLL Area: Non Lexical Lifetimes (NLL) C-bug Category: This is a bug. NLL-diagnostics Working torwads the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Riateche
Copy link

Riateche commented Apr 1, 2019

Code:

fn main() {
    let mut i = 0;
    [].iter().for_each(|_: &i32| {
        [].iter().for_each(move |_: &i32| {
            i += 1;
        });
    });
}

Output:

warning: variable does not need to be mutable
 --> src/main.rs:3:9
  |
3 |     let mut i = 0;
  |         ----^
  |         |
  |         help: remove this `mut`
  |
  = note: #[warn(unused_mut)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 1.26s
     Running `target/debug/playground`

Removing mut breaks the code.

@jonas-schievink jonas-schievink added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Apr 1, 2019
@matthewjasper matthewjasper added A-NLL Area: Non Lexical Lifetimes (NLL) NLL-diagnostics Working torwads the "diagnostic parity" goal labels Apr 1, 2019
@matthewjasper matthewjasper self-assigned this Apr 2, 2019
Centril added a commit to Centril/rust that referenced this issue Apr 8, 2019
…-mut, r=pnkfelix

Mark variables captured by reference as mutable correctly

Closes rust-lang#59620

r? @pnkfelix
cramertj added a commit to cramertj/rust that referenced this issue Apr 11, 2019
…-mut, r=pnkfelix

Mark variables captured by reference as mutable correctly

Closes rust-lang#59620

r? @pnkfelix
Centril added a commit to Centril/rust that referenced this issue Apr 12, 2019
…-mut, r=pnkfelix

Mark variables captured by reference as mutable correctly

Closes rust-lang#59620

r? @pnkfelix
Centril added a commit to Centril/rust that referenced this issue Apr 13, 2019
…-mut, r=pnkfelix

Mark variables captured by reference as mutable correctly

Closes rust-lang#59620

r? @pnkfelix
Centril added a commit to Centril/rust that referenced this issue Apr 13, 2019
…-mut, r=pnkfelix

Mark variables captured by reference as mutable correctly

Closes rust-lang#59620

r? @pnkfelix
Centril added a commit to Centril/rust that referenced this issue Apr 13, 2019
…-mut, r=pnkfelix

Mark variables captured by reference as mutable correctly

Closes rust-lang#59620

r? @pnkfelix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-NLL Area: Non Lexical Lifetimes (NLL) C-bug Category: This is a bug. NLL-diagnostics Working torwads the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants