rust-clippy
rust-clippy copied to clipboard
`expect` attribute supressing lint, but then saying it's not fulfilled
NOTE: This is using cargo clippy, but the actual issue may be in the lint_reasons feature. If this is not appropriate for the rustc repo, let me know and I can copy it over to clippy's.
I tried this code:
#![feature(lint_reasons)]
fn main() {
if true {
#[expect(clippy::needless_return)]
return;
}
}
playground (Use Clippy)
I expected to see this happen: No output because clippy emits the clippy::needless_return lint, which should satisfy the expect.
Instead, this happened:
warning: this lint expectation is unfulfilled
--> src/main.rs:5:18
|
5 | #[expect(clippy::needless_return)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
Meta
rustc --version --verbose:
rustc 1.77.0-nightly (2df6406b8 2023-12-26)
binary: rustc
commit-hash: 2df6406b886757a3c1475957660a3a4ae6c786de
commit-date: 2023-12-26
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6
@rustbot label +T-compiler +A-clippy +A-lint +F-lint_reasons
This may be a bug in clippy's implementation of the lint: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Possible.20bug.3F/near/410324973
This is a most likely a bug in Clippy. The old playground link from the issue doesn't work anymore, but here is a new working one: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=c87895279ad49e3067a5ec9c812bf6a9
The problem is likely that the lint is not emitted at the right place. I'll transfer it to the Clippy repo.
Error: Label F-lint_reasons can only be set by Rust team members
Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.
Lol, yep found the corporate:
if !cx.tcx.hir().attrs(expr.hir_id).is_empty() {
return;
}
The lint is apparently suppressed if there is any attribute on the return. Now comes the fun part of figuring out why xD
Ignoring attributes seem to be intentional: https://github.com/rust-lang/rust-clippy/issues/9361
I can still make it work for #[expect] attrs: