Skip to content

Commit 037199b

Browse files
committed
detect allow_attributes on internal attributes
1 parent e8b78e2 commit 037199b

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

clippy_lints/src/attrs/allow_attributes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
use super::ALLOW_ATTRIBUTES;
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::is_from_proc_macro;
4-
use rustc_ast::{AttrStyle, Attribute};
4+
use rustc_ast::Attribute;
55
use rustc_errors::Applicability;
66
use rustc_lint::{LateContext, LintContext};
77
use rustc_middle::lint::in_external_macro;
88

99
// Separate each crate's features.
1010
pub fn check<'cx>(cx: &LateContext<'cx>, attr: &'cx Attribute) {
1111
if !in_external_macro(cx.sess(), attr.span)
12-
&& let AttrStyle::Outer = attr.style
1312
&& let Some(ident) = attr.ident()
1413
&& !is_from_proc_macro(cx, attr)
1514
{

tests/ui/allow_attributes.fixed

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@aux-build:proc_macros.rs
22
//@aux-build:proc_macro_derive.rs
3-
#![allow(unused)]
3+
#![expect(unused)]
44
#![warn(clippy::allow_attributes)]
55
#![no_main]
66

@@ -45,7 +45,7 @@ fn ignore_proc_macro() {
4545
}
4646

4747
fn ignore_inner_attr() {
48-
#![allow(unused)] // Should not lint
48+
#![expect(unused)]
4949
}
5050

5151
#[clippy::msrv = "1.81"]

tests/ui/allow_attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn ignore_proc_macro() {
4545
}
4646

4747
fn ignore_inner_attr() {
48-
#![allow(unused)] // Should not lint
48+
#![allow(unused)]
4949
}
5050

5151
#[clippy::msrv = "1.81"]

tests/ui/allow_attributes.stderr

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
error: #[allow] attribute found
2-
--> tests/ui/allow_attributes.rs:13:3
2+
--> tests/ui/allow_attributes.rs:3:4
33
|
4-
LL | #[allow(dead_code)]
5-
| ^^^^^ help: replace it with: `expect`
4+
LL | #![allow(unused)]
5+
| ^^^^^ help: replace it with: `expect`
66
|
77
= note: `-D clippy::allow-attributes` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::allow_attributes)]`
99

10+
error: #[allow] attribute found
11+
--> tests/ui/allow_attributes.rs:13:3
12+
|
13+
LL | #[allow(dead_code)]
14+
| ^^^^^ help: replace it with: `expect`
15+
1016
error: #[allow] attribute found
1117
--> tests/ui/allow_attributes.rs:22:30
1218
|
1319
LL | #[cfg_attr(panic = "unwind", allow(dead_code))]
1420
| ^^^^^ help: replace it with: `expect`
1521

22+
error: #[allow] attribute found
23+
--> tests/ui/allow_attributes.rs:48:8
24+
|
25+
LL | #![allow(unused)]
26+
| ^^^^^ help: replace it with: `expect`
27+
1628
error: #[allow] attribute found
1729
--> tests/ui/allow_attributes.rs:53:7
1830
|
@@ -27,5 +39,5 @@ LL | #[allow(unused)]
2739
|
2840
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
2941

30-
error: aborting due to 4 previous errors
42+
error: aborting due to 6 previous errors
3143

0 commit comments

Comments
 (0)