-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.