Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/test/ui/suggestions/option_as_ref.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// run-rustfix

fn _foo(opt: &Option<Box<i32>>) -> String {
opt.as_ref().map(|x| x.to_string()).unwrap_or_else(String::new)
//~^ cannot move out of `*opt` which is behind a shared reference
}

fn main(){}
8 changes: 8 additions & 0 deletions src/test/ui/suggestions/option_as_ref.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// run-rustfix

fn _foo(opt: &Option<Box<i32>>) -> String {
opt.map(|x| x.to_string()).unwrap_or_else(String::new)
//~^ cannot move out of `*opt` which is behind a shared reference
}

fn main(){}
22 changes: 22 additions & 0 deletions src/test/ui/suggestions/option_as_ref.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0507]: cannot move out of `*opt` which is behind a shared reference
--> $DIR/option_as_ref.rs:4:5
|
LL | opt.map(|x| x.to_string()).unwrap_or_else(String::new)
| ^^^^----------------------
| | |
| | `*opt` moved due to this method call
| move occurs because `*opt` has type `Option<Box<i32>>`, which does not implement the `Copy` trait
|
note: this function takes ownership of the receiver `self`, which moves `*opt`
--> $SRC_DIR/core/src/option.rs:LL:COL
|
LL | pub const fn map<U, F>(self, f: F) -> Option<U>
| ^^^^
help: consider calling `.as_ref()` to borrow the type's contents
|
LL | opt.as_ref().map(|x| x.to_string()).unwrap_or_else(String::new)
| +++++++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0507`.