diff --git a/src/test/ui/suggestions/option_as_ref.fixed b/src/test/ui/suggestions/option_as_ref.fixed new file mode 100644 index 0000000000000..2bfc8073c2fab --- /dev/null +++ b/src/test/ui/suggestions/option_as_ref.fixed @@ -0,0 +1,8 @@ +// run-rustfix + +fn _foo(opt: &Option>) -> 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(){} diff --git a/src/test/ui/suggestions/option_as_ref.rs b/src/test/ui/suggestions/option_as_ref.rs new file mode 100644 index 0000000000000..3ca11f84d7f08 --- /dev/null +++ b/src/test/ui/suggestions/option_as_ref.rs @@ -0,0 +1,8 @@ +// run-rustfix + +fn _foo(opt: &Option>) -> 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(){} diff --git a/src/test/ui/suggestions/option_as_ref.stderr b/src/test/ui/suggestions/option_as_ref.stderr new file mode 100644 index 0000000000000..ee13998ebf1de --- /dev/null +++ b/src/test/ui/suggestions/option_as_ref.stderr @@ -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>`, 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(self, f: F) -> Option + | ^^^^ +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`.