@@ -12,7 +12,7 @@ use rustc_ast::{self as ast, DUMMY_NODE_ID, NodeId};
1212use rustc_ast_pretty:: pprust;
1313use rustc_attr_data_structures:: { AttributeKind , find_attr} ;
1414use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
15- use rustc_errors:: { Applicability , Diag , ErrorGuaranteed } ;
15+ use rustc_errors:: { Applicability , Diag , ErrorGuaranteed , MultiSpan } ;
1616use rustc_feature:: Features ;
1717use rustc_hir as hir;
1818use rustc_lint_defs:: BuiltinLintDiag ;
@@ -129,7 +129,13 @@ pub(super) enum MacroRule {
129129 /// A function-style rule, for use with `m!()`
130130 Func { lhs : Vec < MatcherLoc > , lhs_span : Span , rhs : mbe:: TokenTree } ,
131131 /// An attr rule, for use with `#[m]`
132- Attr { args : Vec < MatcherLoc > , body : Vec < MatcherLoc > , lhs_span : Span , rhs : mbe:: TokenTree } ,
132+ Attr {
133+ args : Vec < MatcherLoc > ,
134+ args_span : Span ,
135+ body : Vec < MatcherLoc > ,
136+ body_span : Span ,
137+ rhs : mbe:: TokenTree ,
138+ } ,
133139}
134140
135141pub struct MacroRulesMacroExpander {
@@ -141,11 +147,15 @@ pub struct MacroRulesMacroExpander {
141147}
142148
143149impl MacroRulesMacroExpander {
144- pub fn get_unused_rule ( & self , rule_i : usize ) -> Option < ( & Ident , Span ) > {
150+ pub fn get_unused_rule ( & self , rule_i : usize ) -> Option < ( & Ident , MultiSpan ) > {
145151 // If the rhs contains an invocation like `compile_error!`, don't report it as unused.
146- let ( MacroRule :: Func { lhs_span, ref rhs, .. } | MacroRule :: Attr { lhs_span, ref rhs, .. } ) =
147- self . rules [ rule_i] ;
148- if has_compile_error_macro ( rhs) { None } else { Some ( ( & self . name , lhs_span) ) }
152+ let ( span, rhs) = match self . rules [ rule_i] {
153+ MacroRule :: Func { lhs_span, ref rhs, .. } => ( MultiSpan :: from_span ( lhs_span) , rhs) ,
154+ MacroRule :: Attr { args_span, body_span, ref rhs, .. } => {
155+ ( MultiSpan :: from_spans ( vec ! [ args_span, body_span] ) , rhs)
156+ }
157+ } ;
158+ if has_compile_error_macro ( rhs) { None } else { Some ( ( & self . name , span) ) }
149159 }
150160}
151161
@@ -594,12 +604,13 @@ pub fn compile_declarative_macro(
594604 return dummy_syn_ext ( guar. unwrap ( ) ) ;
595605 } ;
596606 if let Some ( args) = args {
597- let lhs_span = args. span ( ) . to ( lhs_span ) ;
607+ let args_span = args. span ( ) ;
598608 let mbe:: TokenTree :: Delimited ( .., delimited) = args else {
599609 return dummy_syn_ext ( guar. unwrap ( ) ) ;
600610 } ;
601611 let args = mbe:: macro_parser:: compute_locs ( & delimited. tts ) ;
602- rules. push ( MacroRule :: Attr { args, body : lhs, lhs_span, rhs : rhs_tt } ) ;
612+ let body_span = lhs_span;
613+ rules. push ( MacroRule :: Attr { args, args_span, body : lhs, body_span, rhs : rhs_tt } ) ;
603614 } else {
604615 rules. push ( MacroRule :: Func { lhs, lhs_span, rhs : rhs_tt } ) ;
605616 }
0 commit comments