-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-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
Summary
Title summarizes sufficiently IMO.
Reproducer
I tried this code:
#[warn(clippy::redundant_closure_for_method_calls)]
fn main() {
let x = Some("42");
let y = x.map(|x| x.parse::<i16>());
println!("{y:?}");
}
I expected to see this happen:
4 | let y = x.map(|x| x.parse::<i16>());
| ^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `str::parse::<i16>`
Instead, this happened:
warning: redundant closure
4 | let y = x.map(|x| x.parse::<i16>());
| ^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `str::parse`
If you follow this suggestion, you get
error[E0283]: type annotations needed
--> src/main.rs:4:19
|
4 | let y = x.map(str::parse);
| ^^^^^^^^^^ cannot infer type of the type parameter `F` declared on the method `parse`
|
= note: cannot satisfy `_: FromStr`
Version
rustc 1.86.0-nightly (bf1b174e7 2025-01-28)
binary: rustc
commit-hash: bf1b174e7d0922fc549071b751ab96fc9ee9f6fe
commit-date: 2025-01-28
host: x86_64-pc-windows-msvc
release: 1.86.0-nightly
LLVM version: 19.1.7
Additional Labels
@rustbot label +I-suggestion-causes-error
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-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