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

Cannot assign to captured outer variable in an FnMut closure diagnostic #41790

Closed
Mark-Simulacrum opened this issue May 6, 2017 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. WG-diagnostics Working group: Diagnostics

Comments

@Mark-Simulacrum
Copy link
Member

fn foo(mut f: Box<FnMut()>) {
    f();
}

fn main() {
    let y = true;
    foo(Box::new(move || y = false) as Box<_>);
}

produces

error: cannot assign to captured outer variable in an `FnMut` closure
 --> test.rs:7:26
  |
7 |     foo(Box::new(move || y = false) as Box<_>);
  |                          ^^^^^^^^^

error: aborting due to previous error

but should produce

error: cannot assign to captured outer variable in an `FnMut` closure
 --> test.rs:7:26
  |
6 |     let y = true;
  |         - use `mut y` here to make mutable
7 |     foo(Box::new(move || y = false) as Box<_>);
  |                          ^^^^^^^^^

error: aborting due to previous error

cc @estebank, you implemented a similar change for moves: #41523.

@sgrif
Copy link
Contributor

sgrif commented Oct 8, 2017

@estebank estebank added E-needs-mentor WG-diagnostics Working group: Diagnostics labels Oct 9, 2017
kennytm added a commit to kennytm/rust that referenced this issue Oct 13, 2017
Point at immutable outer variable

When attempting to mutate an immutable outer variable from a closure,
point at the outer variable and suggest making it mutable.

Fix rust-lang#41790.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

No branches or pull requests

3 participants