Skip to content

option_map_unwrap_or lint suggestion does not compile #2686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
idubrov opened this issue Apr 20, 2018 · 0 comments
Closed

option_map_unwrap_or lint suggestion does not compile #2686

idubrov opened this issue Apr 20, 2018 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@idubrov
Copy link

idubrov commented Apr 20, 2018

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
@phansch phansch added C-bug Category: Clippy is not doing the correct thing L-suggestion Lint: Improving, adding or fixing lint suggestions labels Apr 21, 2018
@phansch phansch added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Jan 4, 2019
bors added a commit that referenced this issue Feb 27, 2019
Only suggest map_or for copy types

Fixes #2686
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

No branches or pull requests

2 participants