diff options
| author | bors <bors@rust-lang.org> | 2022-03-04 19:23:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-03-04 19:23:39 +0000 |
| commit | 48d54942f55078cd5866a96bd182bbaf2b81d0f6 (patch) | |
| tree | c357a5c99c1bdc6cd876a8dae73551e0742437a5 /tests/ui | |
| parent | 53189ad190f313cbad28f8138a04e734ac052cfc (diff) | |
| parent | ab6ffb6371b78d1777b90c25a44163562ae53036 (diff) | |
| download | rust-48d54942f55078cd5866a96bd182bbaf2b81d0f6.tar.gz rust-48d54942f55078cd5866a96bd182bbaf2b81d0f6.zip | |
Auto merge of #8504 - xFrednet:8502-allow-lint-without-reason, r=flip1995
Add lint to detect `allow` attributes without reason I was considering putting this lint into the pedantic group. However, that would result in countless warnings for existing projects. Having it in restriction also seems good to me :upside_down_face: (And now I need sleep :zzz: ) --- changelog: New lint [`allow_lint_without_reason`] (Requires the `lint_reasons` feature) Closes: rust-lang/rust-clippy#8502
Diffstat (limited to 'tests/ui')
| -rw-r--r-- | tests/ui/allow_attributes_without_reason.rs | 14 | ||||
| -rw-r--r-- | tests/ui/allow_attributes_without_reason.stderr | 23 |
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/ui/allow_attributes_without_reason.rs b/tests/ui/allow_attributes_without_reason.rs new file mode 100644 index 00000000000..1a0d4e88657 --- /dev/null +++ b/tests/ui/allow_attributes_without_reason.rs @@ -0,0 +1,14 @@ +#![feature(lint_reasons)] +#![deny(clippy::allow_attributes_without_reason)] + +// These should trigger the lint +#[allow(dead_code)] +#[allow(dead_code, deprecated)] +// These should be fine +#[allow(dead_code, reason = "This should be allowed")] +#[warn(dyn_drop, reason = "Warnings can also have reasons")] +#[warn(deref_nullptr)] +#[deny(deref_nullptr)] +#[forbid(deref_nullptr)] + +fn main() {} diff --git a/tests/ui/allow_attributes_without_reason.stderr b/tests/ui/allow_attributes_without_reason.stderr new file mode 100644 index 00000000000..cd040a144aa --- /dev/null +++ b/tests/ui/allow_attributes_without_reason.stderr @@ -0,0 +1,23 @@ +error: `allow` attribute without specifying a reason + --> $DIR/allow_attributes_without_reason.rs:5:1 + | +LL | #[allow(dead_code)] + | ^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/allow_attributes_without_reason.rs:2:9 + | +LL | #![deny(clippy::allow_attributes_without_reason)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: try adding a reason at the end with `, reason = ".."` + +error: `allow` attribute without specifying a reason + --> $DIR/allow_attributes_without_reason.rs:6:1 + | +LL | #[allow(dead_code, deprecated)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: try adding a reason at the end with `, reason = ".."` + +error: aborting due to 2 previous errors + |
