-
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 lintsC-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
Given the following code: (playground)
fn foo(a: &Option<String>, b: &Option<String>) {
match (a, b) {
(None, &c) | (&c, None) => &c.unwrap(),
(&Some(ref c), _) => c,
};
}
The current output is:
error[E0507]: cannot move out of a shared reference
--> src/lib.rs:2:11
|
2 | match (a, b) {
| ^^^^^^ help: consider borrowing the `Option`'s content: `(a, b).as_ref()`
3 | (None, &c) | (&c, None) => &c.unwrap(),
| -
| |
| data moved here
| move occurs because `c` has type `Option<String>`, which does not implement the `Copy` trait
The suggestion does not compile. Presumably it should suggest (a.as_ref(), b.as_ref())
.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-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.