`assert_is_empty` suggestion missing type annotations

Open
#17,676 7 comments 0 reactions 1 assignee View on GitHub

@ABHINAB-CHHETRI is already working on this.

Since Sep 3, 2026.

Assessment

This issue has not been assessed yet.

Description

C-bug I-suggestion-causes-error
Summary

assert_is_empty suggests [] as a replacement, but the resulting code can fail to compile because the array element type cannot be inferred.

Reproducer

Code:

pub fn issue17676(v: &[&str]) {
    assert!(v.is_empty());
}

Current output:

pub fn issue17676(v: &[&str]) {
    assert_eq!(v, []);
}
error[E0282]: type annotations needed
 --> <source>:2:5
  |
2 |     assert_eq!(v, []);
  |     ^^^^^^^^^^^^^^^^^ cannot infer type

Desired output:

pub fn f(v: &[&str]) {
    assert_eq!(v, [""; 0]);
}

https://rust.godbolt.org/z/eG4MTGK5n

Version
clippy 0.1.100 (5db7f4be8a 2026-09-01)
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

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.

More from rust-lang/rust-clippy

All issues in rust-lang/rust-clippy

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.