File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ // run-rustfix
2+
3+ fn _foo(opt: &Option<Box<i32>>) -> String {
4+ opt.as_ref().map(|x| x.to_string()).unwrap_or_else(String::new)
5+ //~^ cannot move out of `*opt` which is behind a shared reference
6+ }
7+
8+ fn main(){}
Original file line number Diff line number Diff line change 1+ // run-rustfix
2+
3+ fn _foo ( opt : & Option < Box < i32 > > ) -> String {
4+ opt. map ( |x| x. to_string ( ) ) . unwrap_or_else ( String :: new)
5+ //~^ cannot move out of `*opt` which is behind a shared reference
6+ }
7+
8+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error[E0507]: cannot move out of `*opt` which is behind a shared reference
2+ --> $DIR/option_as_ref.rs:4:5
3+ |
4+ LL | opt.map(|x| x.to_string()).unwrap_or_else(String::new)
5+ | ^^^^----------------------
6+ | | |
7+ | | `*opt` moved due to this method call
8+ | move occurs because `*opt` has type `Option<Box<i32>>`, which does not implement the `Copy` trait
9+ |
10+ note: this function takes ownership of the receiver `self`, which moves `*opt`
11+ --> $SRC_DIR/core/src/option.rs:LL:COL
12+ |
13+ LL | pub const fn map<U, F>(self, f: F) -> Option<U>
14+ | ^^^^
15+ help: consider calling `.as_ref()` to borrow the type's contents
16+ |
17+ LL | opt.as_ref().map(|x| x.to_string()).unwrap_or_else(String::new)
18+ | +++++++++
19+
20+ error: aborting due to previous error
21+
22+ For more information about this error, try `rustc --explain E0507`.
You can’t perform that action at this time.
0 commit comments