-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.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.
Milestone
Description
Code
Playground (regressed rustc version)
fn foo(opt: &Option<Box<i32>>) -> String {
opt.map(|x| x.to_string()).unwrap_or_else(String::new)
}
Output (stable 1.56.0, good)
error[E0507]: cannot move out of `*opt` which is behind a shared reference
--> src/lib.rs:2:5
|
2 | opt.map(|x| x.to_string()).unwrap_or_else(String::new)
| ^^^ move occurs because `*opt` has type `Option<Box<i32>>`, which does not implement the `Copy` trait
|
help: consider borrowing the `Option`'s content
|
2 | opt.as_ref().map(|x| x.to_string()).unwrap_or_else(String::new)
| +++++++++
For more information about this error, try `rustc --explain E0507`.
Output (beta 1.57.0-beta.2, incorrect)
error[E0507]: cannot move out of `*opt` which is behind a shared reference
--> src/lib.rs:2:5
|
2 | opt.map(|x| x.to_string()).unwrap_or_else(String::new)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ move occurs because `*opt` has type `Option<Box<i32>>`, which does not implement the `Copy` trait
|
help: consider borrowing the `Option`'s content
|
2 | opt.map(|x| x.to_string()).as_ref().unwrap_or_else(String::new)
| +++++++++
For more information about this error, try `rustc --explain E0507`.
fogti and mpfaff
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.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.