Skip to content

Commit

Permalink
Rollup merge of rust-lang#100773 - WaffleLapkin:addasreftest, r=TaKO8Ki
Browse files Browse the repository at this point in the history
add a ui test for `.as_ref` suggestion

Closes rust-lang#90286
  • Loading branch information
matthiaskrgr authored Aug 20, 2022
2 parents c4d57f5 + 622e425 commit e5b9afc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
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`.

0 comments on commit e5b9afc

Please sign in to comment.