-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #94580 - xFrednet:55112-only-reason-in-lint-attr, r=lcnr
Emit `unused_attributes` if a level attr only has a reason Fixes a comment from `compiler/rustc_lint/src/levels.rs`. Lint level attributes that only contain a reason will also trigger the `unused_attribute` lint. The lint now also checks for the `expect` lint level. That's it, have a great rest of the day for everyone reasoning this 🙃 cc: #55112
- Loading branch information
Showing
6 changed files
with
133 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,71 @@ | ||
error: unused attribute | ||
--> $DIR/empty-attributes.rs:8:1 | ||
--> $DIR/empty-attributes.rs:11:1 | ||
| | ||
LL | #[repr()] | ||
| ^^^^^^^^^ help: remove this attribute | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/empty-attributes.rs:1:9 | ||
--> $DIR/empty-attributes.rs:3:9 | ||
| | ||
LL | #![deny(unused_attributes)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
= note: attribute `repr` with an empty list has no effect | ||
|
||
error: unused attribute | ||
--> $DIR/empty-attributes.rs:11:1 | ||
--> $DIR/empty-attributes.rs:14:1 | ||
| | ||
LL | #[target_feature()] | ||
| ^^^^^^^^^^^^^^^^^^^ help: remove this attribute | ||
| | ||
= note: attribute `target_feature` with an empty list has no effect | ||
|
||
error: unused attribute | ||
--> $DIR/empty-attributes.rs:2:1 | ||
--> $DIR/empty-attributes.rs:4:1 | ||
| | ||
LL | #![allow()] | ||
| ^^^^^^^^^^^ help: remove this attribute | ||
| | ||
= note: attribute `allow` with an empty list has no effect | ||
|
||
error: unused attribute | ||
--> $DIR/empty-attributes.rs:3:1 | ||
--> $DIR/empty-attributes.rs:5:1 | ||
| | ||
LL | #![expect()] | ||
| ^^^^^^^^^^^^ help: remove this attribute | ||
| | ||
= note: attribute `expect` with an empty list has no effect | ||
|
||
error: unused attribute | ||
--> $DIR/empty-attributes.rs:6:1 | ||
| | ||
LL | #![warn()] | ||
| ^^^^^^^^^^ help: remove this attribute | ||
| | ||
= note: attribute `warn` with an empty list has no effect | ||
|
||
error: unused attribute | ||
--> $DIR/empty-attributes.rs:4:1 | ||
--> $DIR/empty-attributes.rs:7:1 | ||
| | ||
LL | #![deny()] | ||
| ^^^^^^^^^^ help: remove this attribute | ||
| | ||
= note: attribute `deny` with an empty list has no effect | ||
|
||
error: unused attribute | ||
--> $DIR/empty-attributes.rs:5:1 | ||
--> $DIR/empty-attributes.rs:8:1 | ||
| | ||
LL | #![forbid()] | ||
| ^^^^^^^^^^^^ help: remove this attribute | ||
| | ||
= note: attribute `forbid` with an empty list has no effect | ||
|
||
error: unused attribute | ||
--> $DIR/empty-attributes.rs:6:1 | ||
--> $DIR/empty-attributes.rs:9:1 | ||
| | ||
LL | #![feature()] | ||
| ^^^^^^^^^^^^^ help: remove this attribute | ||
| | ||
= note: attribute `feature` with an empty list has no effect | ||
|
||
error: aborting due to 7 previous errors | ||
error: aborting due to 8 previous errors | ||
|
14 changes: 14 additions & 0 deletions
14
src/test/ui/lint/rfc-2383-lint-reason/lint-attribute-only-with-reason.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#![feature(lint_reasons)] | ||
|
||
#![deny(unused_attributes)] | ||
|
||
#[allow(reason = "I want to allow something")]//~ ERROR unused attribute | ||
#[expect(reason = "I don't know what I'm waiting for")]//~ ERROR unused attribute | ||
#[warn(reason = "This should be warn by default")]//~ ERROR unused attribute | ||
#[deny(reason = "All listed lints are denied")]//~ ERROR unused attribute | ||
#[forbid(reason = "Just some reason")]//~ ERROR unused attribute | ||
|
||
#[allow(clippy::box_collection, reason = "This is still valid")] | ||
#[warn(dead_code, reason = "This is also reasonable")] | ||
|
||
fn main() {} |
47 changes: 47 additions & 0 deletions
47
src/test/ui/lint/rfc-2383-lint-reason/lint-attribute-only-with-reason.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
error: unused attribute | ||
--> $DIR/lint-attribute-only-with-reason.rs:5:1 | ||
| | ||
LL | #[allow(reason = "I want to allow something")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/lint-attribute-only-with-reason.rs:3:9 | ||
| | ||
LL | #![deny(unused_attributes)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
= note: attribute `allow` without any lints has no effect | ||
|
||
error: unused attribute | ||
--> $DIR/lint-attribute-only-with-reason.rs:6:1 | ||
| | ||
LL | #[expect(reason = "I don't know what I'm waiting for")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | ||
| | ||
= note: attribute `expect` without any lints has no effect | ||
|
||
error: unused attribute | ||
--> $DIR/lint-attribute-only-with-reason.rs:7:1 | ||
| | ||
LL | #[warn(reason = "This should be warn by default")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | ||
| | ||
= note: attribute `warn` without any lints has no effect | ||
|
||
error: unused attribute | ||
--> $DIR/lint-attribute-only-with-reason.rs:8:1 | ||
| | ||
LL | #[deny(reason = "All listed lints are denied")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | ||
| | ||
= note: attribute `deny` without any lints has no effect | ||
|
||
error: unused attribute | ||
--> $DIR/lint-attribute-only-with-reason.rs:9:1 | ||
| | ||
LL | #[forbid(reason = "Just some reason")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | ||
| | ||
= note: attribute `forbid` without any lints has no effect | ||
|
||
error: aborting due to 5 previous errors | ||
|