-
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-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't
Description
Summary
warn if there's a missed opportunity to make the code more clean and avoid an unnecessary unwrap. Even if you're using unwraps as a temporary placeholder before adding a full option handling later, you can't use this as an excuse to write your code the way that the propsed lint warns against because the concision level is superior with the approach I expected
Lint Name
unnecessary_unwrap
Reproducer
I tried this code:
if option.is_some() {
let content = option.unwrap();
do_something(content);
}
I expected to see this happen:
give warning that suggests rewriting to this;
if let Some(content) = option {
do_something(content);
}
Instead, this happened:
silence
Version
rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't