Skip to content

False positive in redundant_closure with turbofish #7861

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
Kobzol opened this issue Oct 22, 2021 · 0 comments · Fixed by #8983
Closed

False positive in redundant_closure with turbofish #7861

Kobzol opened this issue Oct 22, 2021 · 0 comments · Fixed by #8983
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@Kobzol
Copy link
Contributor

Kobzol commented Oct 22, 2021

Lint name: redundant_closure

I tried this code:

struct A;
trait Trait {}
impl Trait for A {}

fn main() {
    let _: Option<Box<dyn Trait>> = Some(A).map::<Box<dyn Trait>, _>(|v| Box::new(v));
}

I expected to see this happen:
No lint is emitted, because changing the corresponding code from map(|v| Box::new(v)) to map(Box::new) breaks compilation.

Instead, this happened:
The following lint was emitted:

warning: redundant closure
 --> src/main.rs:8:70
  |
8 |     let _: Option<Box<dyn Trait>> = Some(A).map::<Box<dyn Trait>, _>(|v| Box::new(v));
  |                                                                      ^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `Box::new`
  |
  = 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

warning: `foo` (bin "foo") generated 1 warning

If the lint is applied, this error is produced during a build:

error[E0271]: type mismatch resolving `<fn(A) -> std::boxed::Box<A> {std::boxed::Box::<A>::new} as std::ops::FnOnce<(A,)>>::Output == std::boxed::Box<dyn Trait>`
 --> src/main.rs:8:45
  |
8 |     let _: Option<Box<dyn Trait>> = Some(A).map::<Box<dyn Trait>, _>(Box::new);
  |                                             ^^^ expected struct `A`, found trait object `dyn Trait`
  |
  = note: expected struct `std::boxed::Box<A>`
             found struct `std::boxed::Box<dyn Trait>`

For more information about this error, try `rustc --explain E0271`.

Meta

Rust version (rustc -Vv):

rustc 1.58.0-nightly (efd048394 2021-10-20)
binary: rustc
commit-hash: efd0483949496b067cd5f7569d1b28cd3d5d3c72
commit-date: 2021-10-20
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0
@Kobzol Kobzol added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Oct 22, 2021
@xFrednet xFrednet added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Oct 22, 2021
@bors bors closed this as completed in b95ce0e Jun 13, 2022
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-false-positive Issue: The lint was triggered on code it shouldn't have 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.

2 participants