@@ -2,14 +2,15 @@ use crate::base::ExtCtxt;
22use crate :: mbe;
33use crate :: mbe:: macro_parser:: { MatchedNonterminal , MatchedSeq , NamedMatch } ;
44
5- use rustc_ast:: ast:: { Ident , MacCall } ;
5+ use rustc_ast:: ast:: MacCall ;
66use rustc_ast:: mut_visit:: { self , MutVisitor } ;
77use rustc_ast:: token:: { self , NtTT , Token } ;
88use rustc_ast:: tokenstream:: { DelimSpan , TokenStream , TokenTree , TreeAndJoint } ;
99use rustc_data_structures:: fx:: FxHashMap ;
1010use rustc_data_structures:: sync:: Lrc ;
1111use rustc_errors:: pluralize;
1212use rustc_span:: hygiene:: { ExpnId , Transparency } ;
13+ use rustc_span:: symbol:: MacroRulesNormalizedIdent ;
1314use rustc_span:: Span ;
1415
1516use smallvec:: { smallvec, SmallVec } ;
@@ -81,7 +82,7 @@ impl Iterator for Frame {
8182/// Along the way, we do some additional error checking.
8283pub ( super ) fn transcribe (
8384 cx : & ExtCtxt < ' _ > ,
84- interp : & FxHashMap < Ident , NamedMatch > ,
85+ interp : & FxHashMap < MacroRulesNormalizedIdent , NamedMatch > ,
8586 src : Vec < mbe:: TokenTree > ,
8687 transparency : Transparency ,
8788) -> TokenStream {
@@ -223,9 +224,10 @@ pub(super) fn transcribe(
223224 }
224225
225226 // Replace the meta-var with the matched token tree from the invocation.
226- mbe:: TokenTree :: MetaVar ( mut sp, mut ident ) => {
227+ mbe:: TokenTree :: MetaVar ( mut sp, mut orignal_ident ) => {
227228 // Find the matched nonterminal from the macro invocation, and use it to replace
228229 // the meta-var.
230+ let ident = MacroRulesNormalizedIdent :: new ( orignal_ident) ;
229231 if let Some ( cur_matched) = lookup_cur_matched ( ident, interp, & repeats) {
230232 if let MatchedNonterminal ( ref nt) = cur_matched {
231233 // FIXME #2887: why do we apply a mark when matching a token tree meta-var
@@ -249,9 +251,9 @@ pub(super) fn transcribe(
249251 // If we aren't able to match the meta-var, we push it back into the result but
250252 // with modified syntax context. (I believe this supports nested macros).
251253 marker. visit_span ( & mut sp) ;
252- marker. visit_ident ( & mut ident ) ;
254+ marker. visit_ident ( & mut orignal_ident ) ;
253255 result. push ( TokenTree :: token ( token:: Dollar , sp) . into ( ) ) ;
254- result. push ( TokenTree :: Token ( Token :: from_ast_ident ( ident ) ) . into ( ) ) ;
256+ result. push ( TokenTree :: Token ( Token :: from_ast_ident ( orignal_ident ) ) . into ( ) ) ;
255257 }
256258 }
257259
@@ -287,8 +289,8 @@ pub(super) fn transcribe(
287289/// into the right place in nested matchers. If we attempt to descend too far, the macro writer has
288290/// made a mistake, and we return `None`.
289291fn lookup_cur_matched < ' a > (
290- ident : Ident ,
291- interpolations : & ' a FxHashMap < Ident , NamedMatch > ,
292+ ident : MacroRulesNormalizedIdent ,
293+ interpolations : & ' a FxHashMap < MacroRulesNormalizedIdent , NamedMatch > ,
292294 repeats : & [ ( usize , usize ) ] ,
293295) -> Option < & ' a NamedMatch > {
294296 interpolations. get ( & ident) . map ( |matched| {
@@ -316,7 +318,7 @@ enum LockstepIterSize {
316318
317319 /// A `MetaVar` with an actual `MatchedSeq`. The length of the match and the name of the
318320 /// meta-var are returned.
319- Constraint ( usize , Ident ) ,
321+ Constraint ( usize , MacroRulesNormalizedIdent ) ,
320322
321323 /// Two `Constraint`s on the same sequence had different lengths. This is an error.
322324 Contradiction ( String ) ,
@@ -360,7 +362,7 @@ impl LockstepIterSize {
360362/// multiple nested matcher sequences.
361363fn lockstep_iter_size (
362364 tree : & mbe:: TokenTree ,
363- interpolations : & FxHashMap < Ident , NamedMatch > ,
365+ interpolations : & FxHashMap < MacroRulesNormalizedIdent , NamedMatch > ,
364366 repeats : & [ ( usize , usize ) ] ,
365367) -> LockstepIterSize {
366368 use mbe:: TokenTree ;
@@ -376,6 +378,7 @@ fn lockstep_iter_size(
376378 } )
377379 }
378380 TokenTree :: MetaVar ( _, name) | TokenTree :: MetaVarDecl ( _, name, _) => {
381+ let name = MacroRulesNormalizedIdent :: new ( name) ;
379382 match lookup_cur_matched ( name, interpolations, repeats) {
380383 Some ( matched) => match matched {
381384 MatchedNonterminal ( _) => LockstepIterSize :: Unconstrained ,
0 commit comments