Skip to content

MIR borrowck: spurious cannot borrow immutable item error with a closure #46160

Closed
@arielb1

Description

@arielb1

e.g. this variant of the test run-pass/issue-16671.rs

fn foo<F: FnOnce()>(_f: F) { }

fn main() {
    let mut var = 0;
    foo(move|| {
        &mut var;
    });
}

Causes this error:

error[E0596]: cannot borrow immutable item `var` as mutable (Mir)
  --> ../src/test/run-pass/issue-16671.rs:18:9
   |
18 |         &mut var;
   |         ^^^^^^^^ cannot borrow as mutable
   |
   = note: Value not mutable causing this error: `_`

error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions