rust-lang / rust-lang/rust-clippy
Detect redundant always successful `assert_eq!`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Detect if assert_eq! always returns succeeds because the same expression is on the left and right side, such as with assert_eq!(a,a).
These type of cases can happen when refactoring and search'n'replacing code, for example we've recently saw a case of this recently:
assert_eq!(mem::size_of::<usize>(), mem::size_of::<usize>());
It would however be important that it only lints on the expressions being exactly identical, so if using a type alias in the above example that should not trigger this lint, example:
type MyType = usize;
assert_eq!(mem::size_of::<usize>(), mem::size_of::<MyType>());
Lint Name
redundant_assert
Category
pedantic
Advantage
Keeping an assert that has no effect is a code smell and negative value as can leave a false sense of safety in tests / coverage and is additional cognitive overhead without any positive effects.
Drawbacks
Likely none.
Probably not that common occurrence, but does happen.
Example
assert_eq!(mem::size_of::<usize>(), mem::size_of::<usize>());
Assert should simply be removed as it has no effect.
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
Begin by locating existing assert_eq! lint handling and test coverage in rust-clippy; the issue names the intended lint as redundant_assert. Confirm that it reports only exactly identical expressions, not equivalent expressions using a type alias, and that the redundant assertion can be removed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100