-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-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 applied
Description
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
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-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 applied