rust-lang / rust-lang/rust-clippy
`assert_is_empty` suggests unnecessary cast for `Vec<_>`
Open
Beginner friendly
Nobody has claimed this yet.
C-bug
L-suggestion
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
assert_is_empty could avoid suggesting an unnecessary cast when the asserted value is a Vec<_>. The suggested empty array can be written directly as [].
Reproducer
Code:
pub fn issue17673(v: Vec<u8>) {
assert!(v.is_empty());
}
Current output:
pub fn issue17673(v: Vec<u8>) {
assert_eq!(v, [] as [u8; 0]);
}
Desired output:
pub fn issue17673(v: Vec<u8>) {
assert_eq!(v, []);
}
https://rust.godbolt.org/z/MEnr8bGMd
Version
clippy 0.1.100 (5db7f4be8a 2026-09-01)
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 with the assert_is_empty lint and reproduce the issue using the Rust example in the report. Find the lint's implementation and existing tests, then update the suggestion so Vec<_> produces [] without a cast; done means the desired output is emitted and the relevant tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100