Closed
Description
In the following case
#![deny(option_map_unwrap_or)]
pub fn main() {
let id: String = "identifier".to_string();
let prefix: Option<&str> = Some("prefix");
let id = prefix.map(|p| format!("{}.{}", p, id)).unwrap_or(id);
}
Clippy suggests the following change:
note: lint level defined here
--> main/src/main.rs:1:9
|
1 | #![deny(option_map_unwrap_or)]
| ^^^^^^^^^^^^^^^^^^^^
= note: replace `map(|p| format!("{}.{}", p, id)).unwrap_or(id)` with `map_or(id, |p| format!("{}.{}", p, id))`
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.186/index.html#option_map_unwrap_or
which would not compile:
error[E0382]: capture of moved value: `id`
--> main/src/main.rs:10:30
|
10 | let id = prefix.map_or(id, |p| format!("{}.{}", p, id));
| -- ^^^ value captured here after move
| |
| value moved here
|
= note: move occurs because `id` has type `std::string::String`, which does not implement the `Copy` trait