RS.CLIPPY.LEN_WITHOUT_IS_EMPTY

Traits or impls with a public `len` method but no corresponding `is_empty` method

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: len_without_is_empty. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for items that implement .len() but not .is_empty().

Why is this bad?

It is good custom to have both methods, because for some data structures, asking about the length will be a costly operation, whereas .is_empty() can usually answer in constant time. Also it used to lead to false positives on the len_zero lint – currently that lint will ignore such entities.

Example

impl X {
    pub fn len(&self) -> usize {
        ..
    }
}