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

Clippy warns twice about unknown lints #6602

Closed
jyn514 opened this issue Jan 17, 2021 · 5 comments · Fixed by rust-lang/rust#85053
Closed

Clippy warns twice about unknown lints #6602

jyn514 opened this issue Jan 17, 2021 · 5 comments · Fixed by rust-lang/rust#85053
Labels
C-bug Category: Clippy is not doing the correct thing E-hard Call for participation: This a hard problem and requires more experience or effort to work on

Comments

@jyn514
Copy link
Member

jyn514 commented Jan 17, 2021

I tried this code:

#[warn(x)]
fn main() {}

I expected to see this happen: Clippy warns once that x is an unknown lint.

Instead, this happened: Clippy warns twice.

warning: unknown lint: `x`
 --> src/main.rs:1:8
  |
1 | #[warn(x)]
  |        ^
  |
  = note: `#[warn(unknown_lints)]` on by default

warning: unknown lint: `x`
 --> src/main.rs:1:8
  |
1 | #[warn(x)]
  |        ^

warning: 2 warnings emitted

Meta

  • cargo clippy -V: 0.1.51 (2021-01-16 8a65184)
  • rustc -V: 1.49.0

See also rust-lang/rust#80524 (comment) - this looks unrelated to the UNKNOWN_CLIPPY_LINTS pass because it shows up even with that disabled.

cc @flip1995

@jyn514 jyn514 added the C-bug Category: Clippy is not doing the correct thing label Jan 17, 2021
@flip1995
Copy link
Member

flip1995 commented Jan 17, 2021

This is not a Clippy issue, but a rustc issue in general. This happens when linting attributes. Somehow rustc diagnostics doesn't realize, that this warning was already emitted and emits it again. rustc diagnostics has code that hashes warnings/errors, to make sure that they are not emitted twice, which for some reason fails for attributes (for the first attribute linted).

@jyn514
Copy link
Member Author

jyn514 commented Jan 17, 2021

@flip1995 this issue doesn't happen with rustdoc:

> rustdoc warn.rs 
warning: unknown lint: `x`
 --> warn.rs:1:8
  |
1 | #[warn(x)]
  |        ^
  |
  = note: `#[warn(unknown_lints)]` on by default

warning: 1 warning emitted

The issue may be caused by rustc, but it's specific to clippy.

@jyn514
Copy link
Member Author

jyn514 commented Jan 17, 2021

rustc diagnostics has code that hashes warnings/errors, to make sure that they are not emitted twice, which for some reason fails for attributes (for the first attribute linted).

This may be true, but rustdoc still only emits one lint even with -Z deduplicate-diagnostics=no.

@flip1995
Copy link
Member

Oh, I see. So Clippy's lint machinery somehow breaks rustc's diagnostics 🤔

@flip1995 flip1995 added the E-hard Call for participation: This a hard problem and requires more experience or effort to work on label Jan 17, 2021
@flip1995
Copy link
Member

I label it as E-hard, since I already put in many hours trying to fix it about 2 years ago and wasn't even able to find the cause.

flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing E-hard Call for participation: This a hard problem and requires more experience or effort to work on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants