From 037199b9feb2da1e72c33f9bc66eb3de372e4087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20D=C3=B6nszelmann?= Date: Fri, 1 Nov 2024 22:46:01 +0100 Subject: [PATCH] detect allow_attributes on internal attributes --- clippy_lints/src/attrs/allow_attributes.rs | 3 +-- tests/ui/allow_attributes.fixed | 4 ++-- tests/ui/allow_attributes.rs | 2 +- tests/ui/allow_attributes.stderr | 20 ++++++++++++++++---- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/attrs/allow_attributes.rs b/clippy_lints/src/attrs/allow_attributes.rs index a5a7b9f74a69..97fb4c7ef19e 100644 --- a/clippy_lints/src/attrs/allow_attributes.rs +++ b/clippy_lints/src/attrs/allow_attributes.rs @@ -1,7 +1,7 @@ use super::ALLOW_ATTRIBUTES; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::is_from_proc_macro; -use rustc_ast::{AttrStyle, Attribute}; +use rustc_ast::Attribute; use rustc_errors::Applicability; use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::in_external_macro; @@ -9,7 +9,6 @@ use rustc_middle::lint::in_external_macro; // Separate each crate's features. pub fn check<'cx>(cx: &LateContext<'cx>, attr: &'cx Attribute) { if !in_external_macro(cx.sess(), attr.span) - && let AttrStyle::Outer = attr.style && let Some(ident) = attr.ident() && !is_from_proc_macro(cx, attr) { diff --git a/tests/ui/allow_attributes.fixed b/tests/ui/allow_attributes.fixed index 8f6c962e2f5b..af9749471b81 100644 --- a/tests/ui/allow_attributes.fixed +++ b/tests/ui/allow_attributes.fixed @@ -1,6 +1,6 @@ //@aux-build:proc_macros.rs //@aux-build:proc_macro_derive.rs -#![allow(unused)] +#![expect(unused)] #![warn(clippy::allow_attributes)] #![no_main] @@ -45,7 +45,7 @@ fn ignore_proc_macro() { } fn ignore_inner_attr() { - #![allow(unused)] // Should not lint + #![expect(unused)] } #[clippy::msrv = "1.81"] diff --git a/tests/ui/allow_attributes.rs b/tests/ui/allow_attributes.rs index cb6c4dcf7158..9d6d1fef018a 100644 --- a/tests/ui/allow_attributes.rs +++ b/tests/ui/allow_attributes.rs @@ -45,7 +45,7 @@ fn ignore_proc_macro() { } fn ignore_inner_attr() { - #![allow(unused)] // Should not lint + #![allow(unused)] } #[clippy::msrv = "1.81"] diff --git a/tests/ui/allow_attributes.stderr b/tests/ui/allow_attributes.stderr index ae1c440da73b..76b11d39ac1b 100644 --- a/tests/ui/allow_attributes.stderr +++ b/tests/ui/allow_attributes.stderr @@ -1,18 +1,30 @@ error: #[allow] attribute found - --> tests/ui/allow_attributes.rs:13:3 + --> tests/ui/allow_attributes.rs:3:4 | -LL | #[allow(dead_code)] - | ^^^^^ help: replace it with: `expect` +LL | #![allow(unused)] + | ^^^^^ help: replace it with: `expect` | = note: `-D clippy::allow-attributes` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::allow_attributes)]` +error: #[allow] attribute found + --> tests/ui/allow_attributes.rs:13:3 + | +LL | #[allow(dead_code)] + | ^^^^^ help: replace it with: `expect` + error: #[allow] attribute found --> tests/ui/allow_attributes.rs:22:30 | LL | #[cfg_attr(panic = "unwind", allow(dead_code))] | ^^^^^ help: replace it with: `expect` +error: #[allow] attribute found + --> tests/ui/allow_attributes.rs:48:8 + | +LL | #![allow(unused)] + | ^^^^^ help: replace it with: `expect` + error: #[allow] attribute found --> tests/ui/allow_attributes.rs:53:7 | @@ -27,5 +39,5 @@ LL | #[allow(unused)] | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: aborting due to 4 previous errors +error: aborting due to 6 previous errors