@@ -11,7 +11,7 @@ use rustc_ast::tokenstream::{self, DelimSpan, TokenStream};
11
11
use rustc_ast:: { self as ast, DUMMY_NODE_ID , NodeId } ;
12
12
use rustc_ast_pretty:: pprust;
13
13
use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
14
- use rustc_errors:: { Applicability , Diag , ErrorGuaranteed } ;
14
+ use rustc_errors:: { Applicability , Diag , ErrorGuaranteed , MultiSpan } ;
15
15
use rustc_feature:: Features ;
16
16
use rustc_hir as hir;
17
17
use rustc_hir:: attrs:: AttributeKind ;
@@ -130,7 +130,13 @@ pub(super) enum MacroRule {
130
130
/// A function-style rule, for use with `m!()`
131
131
Func { lhs : Vec < MatcherLoc > , lhs_span : Span , rhs : mbe:: TokenTree } ,
132
132
/// An attr rule, for use with `#[m]`
133
- Attr { args : Vec < MatcherLoc > , body : Vec < MatcherLoc > , lhs_span : Span , rhs : mbe:: TokenTree } ,
133
+ Attr {
134
+ args : Vec < MatcherLoc > ,
135
+ args_span : Span ,
136
+ body : Vec < MatcherLoc > ,
137
+ body_span : Span ,
138
+ rhs : mbe:: TokenTree ,
139
+ } ,
134
140
}
135
141
136
142
pub struct MacroRulesMacroExpander {
@@ -142,11 +148,15 @@ pub struct MacroRulesMacroExpander {
142
148
}
143
149
144
150
impl MacroRulesMacroExpander {
145
- pub fn get_unused_rule ( & self , rule_i : usize ) -> Option < ( & Ident , Span ) > {
151
+ pub fn get_unused_rule ( & self , rule_i : usize ) -> Option < ( & Ident , MultiSpan ) > {
146
152
// If the rhs contains an invocation like `compile_error!`, don't report it as unused.
147
- let ( MacroRule :: Func { lhs_span, ref rhs, .. } | MacroRule :: Attr { lhs_span, ref rhs, .. } ) =
148
- self . rules [ rule_i] ;
149
- if has_compile_error_macro ( rhs) { None } else { Some ( ( & self . name , lhs_span) ) }
153
+ let ( span, rhs) = match self . rules [ rule_i] {
154
+ MacroRule :: Func { lhs_span, ref rhs, .. } => ( MultiSpan :: from_span ( lhs_span) , rhs) ,
155
+ MacroRule :: Attr { args_span, body_span, ref rhs, .. } => {
156
+ ( MultiSpan :: from_spans ( vec ! [ args_span, body_span] ) , rhs)
157
+ }
158
+ } ;
159
+ if has_compile_error_macro ( rhs) { None } else { Some ( ( & self . name , span) ) }
150
160
}
151
161
}
152
162
@@ -595,12 +605,13 @@ pub fn compile_declarative_macro(
595
605
return dummy_syn_ext ( guar. unwrap ( ) ) ;
596
606
} ;
597
607
if let Some ( args) = args {
598
- let lhs_span = args. span ( ) . to ( lhs_span ) ;
608
+ let args_span = args. span ( ) ;
599
609
let mbe:: TokenTree :: Delimited ( .., delimited) = args else {
600
610
return dummy_syn_ext ( guar. unwrap ( ) ) ;
601
611
} ;
602
612
let args = mbe:: macro_parser:: compute_locs ( & delimited. tts ) ;
603
- rules. push ( MacroRule :: Attr { args, body : lhs, lhs_span, rhs : rhs_tt } ) ;
613
+ let body_span = lhs_span;
614
+ rules. push ( MacroRule :: Attr { args, args_span, body : lhs, body_span, rhs : rhs_tt } ) ;
604
615
} else {
605
616
rules. push ( MacroRule :: Func { lhs, lhs_span, rhs : rhs_tt } ) ;
606
617
}
0 commit comments