Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expect attribute supressing lint, but then saying it's not fulfilled #12998

Closed
asquared31415 opened this issue Dec 27, 2023 · 5 comments · Fixed by #13027
Closed

expect attribute supressing lint, but then saying it's not fulfilled #12998

asquared31415 opened this issue Dec 27, 2023 · 5 comments · Fixed by #13027
Assignees
Labels
A-clippy A-lint Area: New lints C-bug Category: Clippy is not doing the correct thing

Comments

@asquared31415
Copy link
Contributor

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

@asquared31415 asquared31415 added the C-bug Category: Clippy is not doing the correct thing label Dec 27, 2023
@rustbot rustbot added A-clippy A-lint Area: New lints labels Dec 27, 2023
@asquared31415
Copy link
Contributor Author

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

@xFrednet
Copy link
Member

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.

@xFrednet xFrednet transferred this issue from rust-lang/rust Jun 26, 2024
@rustbot

This comment was marked as off-topic.

@xFrednet
Copy link
Member

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

@xFrednet xFrednet self-assigned this Jun 30, 2024
@xFrednet
Copy link
Member

Ignoring attributes seem to be intentional: #9361

I can still make it work for #[expect] attrs:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-clippy A-lint Area: New lints C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants