-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a ui test for
.as_ref
suggestion
- Loading branch information
1 parent
6c943ba
commit 622e425
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(){} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(){} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |