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

Point to closure when emitting 'cannot move out' for captured variable #87456

Closed
Aaron1011 opened this issue Jul 25, 2021 · 0 comments · Fixed by #87460
Closed

Point to closure when emitting 'cannot move out' for captured variable #87456

Aaron1011 opened this issue Jul 25, 2021 · 0 comments · Fixed by #87460
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

Given the following code: (playground):

fn take_mut(_val: impl FnMut()) {}

fn main() {
    let val = String::new();
    take_mut(|| {
        let _foo: String = val;
    })
}

The current output is:

error[E0507]: cannot move out of `val`, a captured variable in an `FnMut` closure
 --> src/main.rs:6:28
  |
4 |     let val = String::new();
  |         --- captured outer variable
5 |     take_mut(|| {
6 |         let _foo: String = val;
  |                            ^^^
  |                            |
  |                            move occurs because `val` has type `String`, which does not implement the `Copy` trait
  |                            help: consider borrowing here: `&val`

However, we do not point to the closure, or explain why it implements FnMut. In a larger function, this can be confusing.

@Aaron1011 Aaron1011 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 25, 2021
@bors bors closed this as completed in aed7f00 Sep 17, 2021
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 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.

1 participant