`assert_is_empty` could catch `BTreeSet`
Summary
Summary
Of all the collections in std::collections, assert_is_empty only fires on Vec. Here is how it can fire on std::collections::BTreeSet.
To make it more obvious which traits are the bare minimum required on a given type, I introduce this trait to allow me to fill collections generically:
trait ElementExists {
const ELEMENT: Self;
}
...and also leave comments explaining which traits are required.
All cases provided will intentionally fail the assertion, since that's the whole point of the lint. The first case in each set will be the case that the lint should fire on, to show the difference in trait bounds (as some collections have innate bounds).
Parent tracking issue: https://github.com/rust-lang/rust-clippy/issues/17660
Lint Name
assert_is_empty
Reproducer
Clippy should suggest replacing the assert shown in *_normal with the assert shown in *_eq or *_matches if the type(s) in the collection meet the new trait bounds.
// T: Ord is implied by the requirements of BTreeSet
fn btreeset_normal<T: ElementExists + Ord>() {
let mut btreeset = BTreeSet::new();
let _: bool = btreeset.insert(T::ELEMENT);
assert!(btreeset.is_empty());
}
// T now needs Debug
fn btreeset_eq<T: ElementExists + Ord + Debug>() {
let mut btreeset = BTreeSet::new();
let _: bool = btreeset.insert(T::ELEMENT);
assert_eq!(btreeset, BTreeSet::new());
}
Version
rustc 1.100.0-nightly (fb6531d55 2026-08-23)
binary: rustc
commit-hash: fb6531d550e0075b9eb9a51464f404805eec87d9
commit-date: 2026-08-23
host: x86_64-unknown-linux-gnu
release: 1.100.0-nightly
LLVM version: 23.1.0
To anyone interested in working on this:
Please be aware that there is already a PR open that would resolve this issue and all the other sub-issues it is related to: https://github.com/rust-lang/rust-clippy/pull/17806. I think we're likely going to ask that PR to reduce its scope (which is part of why we broke it up into smaller issues), but maybe try talking to the author before doing anything. They haven't been super active lately, so if you don't hear anything in 2 weeks, I think you can move forward.
I am NOT a rust-clippy maintainer, and you CAN and SHOULD claim this issue with @rustbot claim if you want to work on it. This is just an unusual situation that has yet to be clarified by the rust-clippy maintainers, so I'm making this suggestion to try to avoid duplicated effort/conflicts.
@rustbot claim