Description
Summary
Most lints are silent when using #[expect(some_lint)]
if that lint isn't enabled.
However, len_without_is_empty
seems to be different. #[expect(clippy::len_without_is_empty)]
will trigger a warning if I run clippy with that lint disabled. Even if the affected code does trigger that lint-- it's just seems unhappy about being disabled.
Reproducer
This code produces no errors when I run cargo clippy
:
pub struct Empty;
impl Empty {
#[expect(clippy::len_without_is_empty)]
pub fn len(&self) -> usize {
0
}
}
#[expect(clippy::bool_comparison)]
pub fn silly(x: bool) {
if x == true {
println!("true");
}
}
But if I run cargo clippy -- -Aclippy::all
I get an unexpected warning:
warning: this lint expectation is unfulfilled
--> src/lib.rs:4:14
|
4 | #[expect(clippy::len_without_is_empty)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
This seems strange: there are two lints being expect
ed here, but only one of them complains when not enabled. As far as I can tell most clippy lints are well-behaved in this condition, and don't trigger warnings when expect
ed but disabled.
Running clippy with -Aclippy::all
doesn't seem like a very useful thing to do, and I agree. The thing that I do actually want to do is something like this:
cargo clippy --fix -- -Aclippy::all -Wclippy::useless_nonzero_new_unchecked
... so that I can capture fixes for that particular lint into a standalone commit. And it seems surprising when I get warnings when some unrelated lint was "unfulfilled" in a spurious way.
Version
cargo 1.86.0 (adf9b6ad1 2025-02-28)
release: 1.86.0
commit-hash: adf9b6ad14cfa10ff680d5806741a144f7163698
commit-date: 2025-02-28
host: x86_64-unknown-linux-gnu
libgit2: 1.9.0 (sys:0.20.0 vendored)
libcurl: 8.12.0-DEV (sys:0.4.79+curl-8.12.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Ubuntu 24.4.0 (noble) [64-bit]
This happens with every stable compiler since 1.81.0 when the `#[expect]` attribute was stabilized.
Additional Labels
No response