Open
Description
Summary
unnecessary_unwrap
lints when the unwrap()
is inside an if option.is_some()
or if option.is_none()
, but does not lint when the condition is an early return and the unwrap()
is in following rather than nested code.
Lint Name
unnecessary_unwrap
Reproducer
I tried this code:
pub fn linted1(input: Option<i32>) {
if input.is_some() {
std::hint::black_box(input.unwrap());
}
}
pub fn linted2(input: Option<i32>) {
if input.is_none() {
} else {
std::hint::black_box(input.unwrap());
}
}
pub fn silent1(input: Option<i32>) {
if input.is_some() {
} else {
return;
}
std::hint::black_box(input.unwrap());
}
pub fn silent2(input: Option<i32>) {
if input.is_none() {
return;
}
std::hint::black_box(input.unwrap());
}
I expected to see this happen: Each of these functions should provoke a warning
Instead, this happened: No warnings on silent1 and silent2
Version
Clippy 0.1.85 (2024-12-09 a224f3807e)
via Rust Playground