Skip to content

Capturing a mut variable and then modifying the variable emits a dead-assignment warning #7966

Closed
@alco

Description

@alco
fn main() {
    let mut a = 5;
    let adder = |x: int| x + a;
    a = 6;
    println(fmt!("%d", adder(1)));
}

---

λ rust run 07-mut-local-closure.rs
07-mut-local-closure.rs:4:4: 4:5 warning: value assigned to `a` is never read [-W dead-assignment (default)]
07-mut-local-closure.rs:4     a = 6;
                              ^
warning: no debug symbols in executable (-arch x86_64)
7

Expected behavior: no warning because the variable is read from in the subsequent adder(1) call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-destructorsArea: Destructors (`Drop`, …)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions