-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-suggestionLint: Improving, adding or fixing lint suggestionsLint: Improving, adding or fixing lint suggestions
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
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-suggestionLint: Improving, adding or fixing lint suggestionsLint: Improving, adding or fixing lint suggestions