-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-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
struct NotCopyable;
fn func<F: FnMut() -> H, H: FnMut()>(_: F) {}
fn parse() {
let mut var = None;
func(|| {
move || {
var = Some(NotCopyable);
}
});
}
gives the error:
error[E0507]: cannot move out of `var`, a captured variable in an `FnMut` closure
--> src/lib.rs:8:9
|
6 | let mut var= None;
| --------- captured outer variable
7 | func(|| {
8 | move || {
| ^^^^^^^
| |
| move out of `var` occurs here
| help: consider borrowing the `Option`'s content: `move ||.as_ref()`
9 | var = Some(NotCopyable);
| -----
| |
| move occurs because `var` has type `std::option::Option<NotCopyable>`, which does not implement the `Copy` trait
| move occurs due to use in closure
Error0507 gives a wrong suggestion here:
help: consider borrowing the `Option`'s content: `move ||.as_ref()`
Metadata
Metadata
Assignees
Labels
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-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.