rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.35k stars 1.53k forks source link

`len_without_is_empty` doesn't fire in 1.82 #13555

Open eric-seppanen opened 3 hours ago

eric-seppanen commented 3 hours ago

Summary

In rust 1.81, the following code triggers the clippy::len_without_is_empty lint. However in the current 1.82 beta, the lint no longer fires. I haven't found any changes that would account for this, and the documentation says this lint is still warn by default.

pub struct Empty;

impl Empty {
    pub fn len(&self) -> usize {
        0
    }
}

rust 1.81:

warning: struct `Empty` has a public `len` method, but no `is_empty` method
 --> src/lib.rs:9:5
  |
9 |     pub fn len(&self) -> usize {
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty
  = note: `#[warn(clippy::len_without_is_empty)]` on by default

rust 1.82: (no lint output)

Reproducer

(See above)

Version

rustc 1.82.0-beta.6 (763ad520c 2024-10-12) binary: rustc commit-hash: 763ad520cc6b831ec98e20f8a8fe85b160ad859d commit-date: 2024-10-12 host: x86_64-unknown-linux-gnu release: 1.82.0-beta.6 LLVM version: 19.1.1

Additional Labels

No response

eric-seppanen commented 3 hours ago

It looks like the lint still works, but isn't actually enabled by default any longer. The following will still trigger it:

cargo +beta clippy -- -Wclippy::len_without_is_empty

So I guess this means it was demoted. Does that mean the documentation is wrong, or I'm reading the docs incorrectly? Or does it mean that the lint is intended to be warn by default but isn't?

y21 commented 3 hours ago

It still fires with all channels in the playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=1dc4370a0d768167b637c8e16d902b06 (although none of them use version 1.82 - current beta is 1.83).

The lint is still in style and has always been there, so that sounds surprising that it only works with -W. Do you have any #[allow]s for clippy::style or clippy::len_without_is_empty that you didn't have for 1.81?

eric-seppanen commented 1 hour ago

Bad luck that I filed this bug on the day that the first 1.83 beta was published :)

I agree that it works on the current (1.83) beta.

I first found the same problem in a production codebase (actually an #[expect(clippy::len_without_is_empty)] that triggered unfulfilled_lint_expectations) and I was able to reproduce it in a standalone project (the example above), that has no other code or attributes.

I'm having trouble figuring out how to get back to the beta toolchain I was running when I filed this bug. I've tried downloading a bunch of beta-2024-10-xx releases and can't find one that manifests this problem. So maybe there was a glitch on my end that led to me not running the version of clippy that I thought?

I'll retest this on stable 1.82 and if it's not there then I'm chasing a ghost and this can be closed.