Skip to content

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

Closed
@Riateche

Description

@Riateche

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.

Metadata

Metadata

Assignees

Labels

A-NLLArea: Non-lexical lifetimes (NLL)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.NLL-diagnosticsWorking towards the "diagnostic parity" goalT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions