Skip to content

Commit 2736c74

Browse files
committed
Use AcceptContext in AttribueParser::check_target
1 parent 269d5b5 commit 2736c74

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
273273
(accept.accept_fn)(&mut cx, args);
274274
if !matches!(cx.stage.should_emit(), ShouldEmit::Nothing) {
275275
Self::check_type(accept.attribute_type, target, &mut cx);
276-
self.check_target(
277-
path.get_attribute_path(),
278-
attr.span,
279-
&accept.allowed_targets,
280-
target,
281-
target_id,
282-
&mut emit_lint,
283-
);
276+
Self::check_target(&accept.allowed_targets, target, &mut cx);
284277
}
285278
}
286279
} else {

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use std::borrow::Cow;
33
use rustc_ast::AttrStyle;
44
use rustc_errors::DiagArgValue;
55
use rustc_feature::{AttributeType, Features};
6-
use rustc_hir::lints::{AttributeLint, AttributeLintKind};
7-
use rustc_hir::{AttrPath, MethodKind, Target};
8-
use rustc_span::Span;
6+
use rustc_hir::lints::AttributeLintKind;
7+
use rustc_hir::{MethodKind, Target};
98

109
use crate::AttributeParser;
1110
use crate::context::{AcceptContext, Stage};
@@ -71,38 +70,34 @@ pub(crate) enum Policy {
7170

7271
impl<'sess, S: Stage> AttributeParser<'sess, S> {
7372
pub(crate) fn check_target(
74-
&self,
75-
attr_name: AttrPath,
76-
attr_span: Span,
7773
allowed_targets: &AllowedTargets,
7874
target: Target,
79-
target_id: S::Id,
80-
mut emit_lint: impl FnMut(AttributeLint<S::Id>),
75+
cx: &mut AcceptContext<'_, 'sess, S>,
8176
) {
8277
match allowed_targets.is_allowed(target) {
8378
AllowedResult::Allowed => {}
8479
AllowedResult::Warn => {
8580
let allowed_targets = allowed_targets.allowed_targets();
86-
let (applied, only) =
87-
allowed_targets_applied(allowed_targets, target, self.features);
88-
emit_lint(AttributeLint {
89-
id: target_id,
90-
span: attr_span,
91-
kind: AttributeLintKind::InvalidTarget {
92-
name: attr_name,
81+
let (applied, only) = allowed_targets_applied(allowed_targets, target, cx.features);
82+
let name = cx.attr_path.clone();
83+
let attr_span = cx.attr_span;
84+
cx.emit_lint(
85+
AttributeLintKind::InvalidTarget {
86+
name,
9387
target,
9488
only: if only { "only " } else { "" },
9589
applied,
9690
},
97-
});
91+
attr_span,
92+
);
9893
}
9994
AllowedResult::Error => {
10095
let allowed_targets = allowed_targets.allowed_targets();
101-
let (applied, only) =
102-
allowed_targets_applied(allowed_targets, target, self.features);
103-
self.dcx().emit_err(InvalidTarget {
104-
span: attr_span,
105-
name: attr_name,
96+
let (applied, only) = allowed_targets_applied(allowed_targets, target, cx.features);
97+
let name = cx.attr_path.clone();
98+
cx.dcx().emit_err(InvalidTarget {
99+
span: cx.attr_span.clone(),
100+
name,
106101
target: target.plural_name(),
107102
only: if only { "only " } else { "" },
108103
applied: DiagArgValue::StrListSepByAnd(

0 commit comments

Comments
 (0)