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 with redundant_closure #4354

Closed
KamilaBorowska opened this issue Aug 8, 2019 · 3 comments · Fixed by #6871
Closed

False positive with redundant_closure #4354

KamilaBorowska opened this issue Aug 8, 2019 · 3 comments · Fixed by #6871
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

@KamilaBorowska
Copy link
Contributor

KamilaBorowska commented Aug 8, 2019

Not sure if it's not a duplicate of some issue, there are a lot of tickets, but this still seems distinct. Tested both on nightly and stable.

~/k/pastebinrun (master|✔) $ cargo clippy -V
clippy 0.0.212 (082cfa7 2019-06-07)
~/k/pastebinrun (master|✔) $ cargo +nightly clippy -V
clippy 0.0.212 (b041511 2019-08-07)

Sample code:

fn callbacker(_: impl Fn(&mut [u8])) {}
fn g<W>(_: W) {}
fn main() {
    callbacker(|w| g(w));
}

Causes the following warning.

    Checking playground v0.0.1 (/playground)
warning: redundant closure found
 --> src/main.rs:4:16
  |
4 |     callbacker(|w| g(w));
  |                ^^^^^^^^ help: remove closure as shown: `g`
  |
  = note: `#[warn(clippy::redundant_closure)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure

The closure cannot be removed as shown.

@KamilaBorowska KamilaBorowska changed the title False positive with redundant_closures False positive with redundant_closure Aug 8, 2019
@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 Dec 25, 2019
@apiraino
Copy link

I think I've found another test case:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=74a6ad88e84f7403129a7cd96801b666

fn main() {
    // forcing cast to String for test purposese
    let _v : Vec<String> = match Some("test,test1,test2") {
        Some(x) => x
            .split(',')
            // clippy suggests this closure is redundant
            .map(|x| String::from(x))
            .collect(),
        None => vec![],
    };
}```

@KamilaBorowska
Copy link
Contributor Author

KamilaBorowska commented Jan 16, 2020

@apiraino This is correct, not a bug, the following code works:

fn main() {
    // forcing cast to String for test purposese
    let _v : Vec<String> = match Some("test,test1,test2") {
        Some(x) => x
            .split(',')
            .map(String::from)
            .collect(),
        None => vec![],
    };
}

@apiraino
Copy link

apiraino commented Jan 16, 2020

oh I am sorry, I had completely misunderstood the suggestion:

6 | .map(|x| String::from(x))
  |      ^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `String::from`

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

Successfully merging a pull request may close this issue.

3 participants