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

detect allow_attributes on internal attributes #13643

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions clippy_lints/src/attrs/allow_attributes.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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;

// 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)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/allow_attributes.fixed
Original file line number Diff line number Diff line change
@@ -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]

Expand Down Expand Up @@ -45,7 +45,7 @@ fn ignore_proc_macro() {
}

fn ignore_inner_attr() {
#![allow(unused)] // Should not lint
#![expect(unused)]
}

#[clippy::msrv = "1.81"]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/allow_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn ignore_proc_macro() {
}

fn ignore_inner_attr() {
#![allow(unused)] // Should not lint
#![allow(unused)]
}

#[clippy::msrv = "1.81"]
Expand Down
20 changes: 16 additions & 4 deletions tests/ui/allow_attributes.stderr
Original file line number Diff line number Diff line change
@@ -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
|
Expand All @@ -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