Skip to content

len_zero should not suggest unstable methods #15890

@kpreid

Description

@kpreid

Summary

The len_zero lint should not suggest unstable methods, at least if the corresponding unstable feature is not enabled (which can never happen if the current toolchain is stable).

Reproducer

I tried this code:

fn test(
    vertices: &mut dyn ExactSizeIterator<Item = u8>,
) -> bool {
    vertices.len() == 0
}

I expected to see this happen: No lint, because while ExactSizeIterator::is_empty() exists, it is unstable.

Instead, this happened:

warning: length comparison to zero
 --> src/lib.rs:4:5
  |
4 |     vertices.len() == 0
  |     ^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `vertices.is_empty()`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
  = note: `#[warn(clippy::len_zero)]` on by default

Taking this suggestion will cause an error because it uses an unstable feature.

Version

rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c4747b02ef996e55082b704c09b970588
commit-date: 2025-09-14
host: aarch64-apple-darwin
release: 1.90.0
LLVM version: 20.1.8

Additional Labels

@rustbot label +I-false-positive

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions