rust-lang / rust-lang/rust-clippy

`assert_is_empty` suggests unnecessary cast for `Vec<_>`

Open Beginner friendly
#17,673 3 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.