rust-lang / rust-lang/rust-clippy
unit_cmp: special handling of assert_eq!(Option.unwrap(), ());
Open
Nobody has claimed this yet.
C-enhancement
L-suggestion
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
pub fn main() {
let x: Option<()> = Some(());
assert_eq!(x.unwrap(), ());
}
Clippy warns here ``assert_eq of unit values detected. This will always succeed, however this code will actually check and panic if x is None.
Can we suggest to replace it with
assert!(x.is_some()) in this case?
Found in cargo codebase of cargo.
clippy 0.0.212 (5cb9833 2019-10-08)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the assert_eq unit-value lint and trace how it handles an Option.unwrap() expression. Add coverage for the shown Option<()> case and verify that the diagnostic suggests assert!(x.is_some()) while retaining the panic behavior for None.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100