Skip to content

unnecessary_unwrap doesn't lint following a binding name #14725

@amab8901

Description

@amab8901

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 thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions