Skip to content
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

false positive map_clone on .map(|x| *x) on Option<Deref<Target=T>> #4824

Closed
drunkirishcoder opened this issue Nov 16, 2019 · 1 comment
Closed
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

Comments

@drunkirishcoder
Copy link

struct S(u16);

impl std::ops::Deref for S {
    type Target = u16;
    
    fn deref(&self) -> &u16 {
        &self.0
    }
}

fn main() {
    let s = Some(S(0));
    let _ = s.map(|v| *v);
}
    Checking playground v0.0.1 (/playground)
warning: You are using an explicit closure for copying elements
  --> src/main.rs:15:13
   |
15 |     let _ = s.map(|v| *v);
   |             ^^^^^^^^^^^^^ help: Consider calling the dedicated `copied` method: `s.copied()`
   |
   = note: `#[warn(clippy::map_clone)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_clone

suggested fix does not compile.

   Compiling playground v0.0.1 (/playground)
error[E0599]: no method named `copied` found for type `std::option::Option<S>` in the current scope
  --> src/main.rs:15:15
   |
15 |     let _ = s.copied();
   |               ^^^^^^ method not found in `std::option::Option<S>`
   |
   = note: the method `copied` exists but the following trait bounds were not satisfied:
           `&mut std::option::Option<S> : std::iter::Iterator`
@JohnTitor JohnTitor added 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 labels Nov 16, 2019
@JohnTitor
Copy link
Member

Fixed by #4937

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
Projects
None yet
Development

No branches or pull requests

2 participants