Skip to content

Commit

Permalink
Auto merge of rust-lang#10683 - Centri3:allow-attributes, r=Alexendoo
Browse files Browse the repository at this point in the history
Fix false positive in `allow_attributes`

This would emit a warning if used in a proc-macro with the feature `lint_reasons` enabled. This is now fixed.

changelog: [`allow_attributes`]: Don't lint if in external macro
  • Loading branch information
bors committed Apr 24, 2023
2 parents 5161c4c + 3045998 commit 4b6fdb4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clippy_lints/src/allow_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use ast::AttrStyle;
use clippy_utils::diagnostics::span_lint_and_sugg;
use rustc_ast as ast;
use rustc_errors::Applicability;
use rustc_lint::{LateContext, LateLintPass};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::{declare_lint_pass, declare_tool_lint};

declare_clippy_lint! {
Expand Down Expand Up @@ -51,6 +52,7 @@ impl LateLintPass<'_> for AllowAttribute {
// Separate each crate's features.
fn check_attribute(&mut self, cx: &LateContext<'_>, attr: &ast::Attribute) {
if_chain! {
if !in_external_macro(cx.sess(), attr.span);
if cx.tcx.features().lint_reasons;
if let AttrStyle::Outer = attr.style;
if let Some(ident) = attr.ident();
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/allow_attributes_false_positive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![warn(clippy::allow_attributes)]
#![feature(lint_reasons)]
#![crate_type = "proc-macro"]

fn main() {}

0 comments on commit 4b6fdb4

Please sign in to comment.