Open
Description
Summary
Some suggestions made by the expect_fun_call
lint fail to type.
Reproducer
I tried this code:
#[deny(clippy::expect_fun_call)]
fn f(x: Option<i32>) {
let s = String::from("foo");
let s = s.as_ref();
_ = x.expect(std::convert::identity(s));
println!("s = {s}");
}
I expected to see this happen: an actionable suggestion
Instead, this happened:
7 | _ = x.expect(std::convert::identity(s));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", std::convert::identity(s).to_string()) })`
When applied, the suggestion doesn't compile:
error[E0282]: type annotations needed for `&_`
--> t.rs:6:9
|
6 | let s = s.as_ref();
| ^
7 | _ = x.unwrap_or_else(|| { panic!("{}", std::convert::identity(s).to_string()) });
| --------- type must be known at this point
Version
rustc 1.90.0-nightly (f26e58023 2025-06-30)
binary: rustc
commit-hash: f26e58023071e71636a3c72ac3a2bf89b1f76706
commit-date: 2025-06-30
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7
Additional Labels
@rustbot label +I-suggestion-causes-error