rust/src/test/ui/suggestions/as-ref-2.rs
Esteban Küber 2763a0541c Suggest .as_ref() on borrow error involving Option/Result
When encountering a E0382 borrow error involving an `Option` or `Result`
provide a suggestion to use `.as_ref()` on the prior move location to
avoid the move.

Fix #84165.
2021-04-19 17:14:37 -07:00

14 lines
223 B
Rust

// run-rustfix
struct Struct;
fn bar(_: &Struct) -> Struct {
Struct
}
fn main() {
let foo = Some(Struct);
let _x: Option<Struct> = foo.map(|s| bar(&s));
let _y = foo; //~ERROR use of moved value: `foo`
}