@@ -3,9 +3,8 @@ use std::borrow::Cow;
33use rustc_ast:: AttrStyle ;
44use rustc_errors:: DiagArgValue ;
55use 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
109use crate :: AttributeParser ;
1110use crate :: context:: { AcceptContext , Stage } ;
@@ -71,38 +70,34 @@ pub(crate) enum Policy {
7170
7271impl < ' 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