Skip to content

Commit 4f2faec

Browse files
Move should_emit check
1 parent d17ce1d commit 4f2faec

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,7 @@ impl<'sess> AttributeParser<'sess> {
412412
(accept.accept_fn)(&mut cx, &args);
413413
finalizers.push(accept.finalizer);
414414

415-
if !matches!(cx.should_emit, ShouldEmit::Nothing) {
416-
Self::check_target(&accept.allowed_targets, &mut cx);
417-
}
415+
Self::check_target(&accept.allowed_targets, &mut cx);
418416
} else {
419417
let attr = AttrItem {
420418
path: attr_path.clone(),

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use rustc_hir::attrs::AttributeKind;
77
use rustc_hir::{AttrItem, Attribute, MethodKind, Target};
88
use rustc_span::{BytePos, FileName, RemapPathScopeComponents, Span, Symbol, sym};
99

10-
use crate::AttributeParser;
1110
use crate::context::AcceptContext;
1211
use crate::errors::{
1312
InvalidAttrAtCrateLevel, InvalidTargetLint, ItemFollowingInnerAttr,
1413
UnsupportedAttributesInWhere,
1514
};
1615
use crate::session_diagnostics::InvalidTarget;
1716
use crate::target_checking::Policy::Allow;
17+
use crate::{AttributeParser, ShouldEmit};
1818

1919
#[derive(Debug)]
2020
pub(crate) enum AllowedTargets {
@@ -92,6 +92,10 @@ impl<'sess> AttributeParser<'sess> {
9292
allowed_targets: &AllowedTargets,
9393
cx: &mut AcceptContext<'_, 'sess>,
9494
) {
95+
if matches!(cx.should_emit, ShouldEmit::Nothing) {
96+
return;
97+
}
98+
9599
// For crate-level attributes we emit a specific set of lints to warn
96100
// people about accidentally not using them on the crate.
97101
if let &AllowedTargets::AllowList(&[Allow(Target::Crate)]) = allowed_targets {

0 commit comments

Comments
 (0)