rust-lang / rust-lang/rust-clippy

`assert_is_empty` must take size into consideration

Open
#17,523 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

I often use vec.is_empty() in tests when vec might contain a few megabytes of data. Replacing it with equality check is a very bad idea since it'll print many megabytes of text on failure.

Lint Name

assert_is_empty

Reproducer

I do not have a reduce example yet, but it is triggered, for example, on this line: https://github.com/nazar-pc/abundance/blob/184e6807a3138939f89a5ba18b550957421eacc1/crates/shared/ab-blake3/src/const_fn.rs#L153

warning: used `debug_assert!` to check that a value is empty
   --> crates/shared/ab-blake3/src/const_fn.rs:153:9
    |
153 |         debug_assert!(input.is_empty());
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assert_is_empty
    = note: `-W clippy::assert-is-empty` implied by `-W clippy::pedantic`
    = help: to override `-W clippy::pedantic` add `#[allow(clippy::assert_is_empty)]`
help: use `debug_assert_eq!` to show the value on failure
    |
153 -         debug_assert!(input.is_empty());
153 +         debug_assert_eq!(input, []);
    |

But input can be gigabytes in size. I have even more tricky cases with reference counted containers and they seem to be even harder to recreate in reduced form. And they will be essentially impossible to check for actual size that is going to be printed in the end. So either this lint is mostly unusable or needs to be applied very conservatively.

Version
rustc 1.99.0-nightly (1a98b1e13 2026-08-07)
binary: rustc
commit-hash: 1a98b1e135b254f209c67d447b6d8bcd56a859e0
commit-date: 2026-08-07
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 23.1.0
Additional Labels

No response

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 the reported debug_assert! at crates/shared/ab-blake3/src/const_fn.rs:153. Reproduce the warning with a large or reference-counted container, then determine when the lint's suggested equality check could print excessive data; done means the lint avoids that unsafe suggestion while preserving useful diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.