Closed
Description
Summary
Redundant closure lint can lose type annotation. This can lead to type annotation needed
error.
Lint Name
redundant_closure
Reproducer
In this rather contrived code
fn id<T>(x: T) -> T {
x
}
fn main() {
let _ = None.map(|x: i32| id(x));
}
Clippy reports the following
warning: redundant closure
[--> src/main.rs:5:22
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#) |
5 | let _ = None.map(|x: i32| id(x));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `id`
|
= 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
But if I do replace it, I get the following error
error[[E0282]](https://doc.rust-lang.org/nightly/error-index.html#E0282): type annotations needed for `Option<T>`
[--> src/lib.rs:5:13
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#) |
5 | let _ = None.map(id);
| - ^^^^ cannot infer type for type parameter `T` declared on the enum `Option`
| |
| consider giving this pattern the explicit type `Option<T>`, where the type parameter `T` is specified
For more information about this error, try `rustc --explain E0282`.
Version
No response
Additional Labels
No response