Closed
Description
Summary
The unnecessary_unwrap
can be emitted twice in a closure.
Reproducer
I tried this code:
fn f(x: Option<String>) {
_ = || {
if x.is_some() {
_ = x.unwrap();
}
};
}
fn main() {
f(Some(String::new()));
}
and ran clippy-driver t.rs -Z deduplicate-diagnostics=no
I expected to see this happen: one unnecessary_unwrap
lint
Instead, this happened:
warning: called `unwrap` on `x` after checking its variant with `is_some`
--> t.rs:4:17
|
3 | if x.is_some() {
| -------------- help: try: `if let Some(<item>) = x`
4 | _ = x.unwrap();
| ^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_unwrap
= note: `#[warn(clippy::unnecessary_unwrap)]` on by default
warning: called `unwrap` on `x` after checking its variant with `is_some`
--> t.rs:4:17
|
3 | if x.is_some() {
| -------------- help: try: `if let Some(<item>) = x`
4 | _ = x.unwrap();
| ^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_unwrap
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
warning: 2 warnings emitted
Version
rustc 1.88.0-nightly (e9f8103f9 2025-05-07)
binary: rustc
commit-hash: e9f8103f93f8ce2fa2c15c0c6796ec821f8ae15d
commit-date: 2025-05-07
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.4
Additional Labels
No response