Closed
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`.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Diagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A structured suggestion resulting in incorrect code.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Relevant to the compiler team, which will review and decide on the PR/issue.