@@ -2,14 +2,15 @@ use crate::base::ExtCtxt;
2
2
use crate :: mbe;
3
3
use crate :: mbe:: macro_parser:: { MatchedNonterminal , MatchedSeq , NamedMatch } ;
4
4
5
- use rustc_ast:: ast:: { Ident , Mac } ;
5
+ use rustc_ast:: ast:: Mac ;
6
6
use rustc_ast:: mut_visit:: { self , MutVisitor } ;
7
7
use rustc_ast:: token:: { self , NtTT , Token } ;
8
8
use rustc_ast:: tokenstream:: { DelimSpan , TokenStream , TokenTree , TreeAndJoint } ;
9
9
use rustc_data_structures:: fx:: FxHashMap ;
10
10
use rustc_data_structures:: sync:: Lrc ;
11
11
use rustc_errors:: pluralize;
12
12
use rustc_span:: hygiene:: { ExpnId , Transparency } ;
13
+ use rustc_span:: symbol:: LegacyIdent ;
13
14
use rustc_span:: Span ;
14
15
15
16
use smallvec:: { smallvec, SmallVec } ;
@@ -81,7 +82,7 @@ impl Iterator for Frame {
81
82
/// Along the way, we do some additional error checking.
82
83
pub ( super ) fn transcribe (
83
84
cx : & ExtCtxt < ' _ > ,
84
- interp : & FxHashMap < Ident , NamedMatch > ,
85
+ interp : & FxHashMap < LegacyIdent , NamedMatch > ,
85
86
src : Vec < mbe:: TokenTree > ,
86
87
transparency : Transparency ,
87
88
) -> TokenStream {
@@ -223,9 +224,10 @@ pub(super) fn transcribe(
223
224
}
224
225
225
226
// 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 ) => {
227
228
// Find the matched nonterminal from the macro invocation, and use it to replace
228
229
// the meta-var.
230
+ let ident = LegacyIdent :: new ( orignal_ident) ;
229
231
if let Some ( cur_matched) = lookup_cur_matched ( ident, interp, & repeats) {
230
232
if let MatchedNonterminal ( ref nt) = cur_matched {
231
233
// FIXME #2887: why do we apply a mark when matching a token tree meta-var
@@ -249,9 +251,9 @@ pub(super) fn transcribe(
249
251
// If we aren't able to match the meta-var, we push it back into the result but
250
252
// with modified syntax context. (I believe this supports nested macros).
251
253
marker. visit_span ( & mut sp) ;
252
- marker. visit_ident ( & mut ident ) ;
254
+ marker. visit_ident ( & mut orignal_ident ) ;
253
255
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 ( ) ) ;
255
257
}
256
258
}
257
259
@@ -287,8 +289,8 @@ pub(super) fn transcribe(
287
289
/// into the right place in nested matchers. If we attempt to descend too far, the macro writer has
288
290
/// made a mistake, and we return `None`.
289
291
fn lookup_cur_matched < ' a > (
290
- ident : Ident ,
291
- interpolations : & ' a FxHashMap < Ident , NamedMatch > ,
292
+ ident : LegacyIdent ,
293
+ interpolations : & ' a FxHashMap < LegacyIdent , NamedMatch > ,
292
294
repeats : & [ ( usize , usize ) ] ,
293
295
) -> Option < & ' a NamedMatch > {
294
296
interpolations. get ( & ident) . map ( |matched| {
@@ -316,7 +318,7 @@ enum LockstepIterSize {
316
318
317
319
/// A `MetaVar` with an actual `MatchedSeq`. The length of the match and the name of the
318
320
/// meta-var are returned.
319
- Constraint ( usize , Ident ) ,
321
+ Constraint ( usize , LegacyIdent ) ,
320
322
321
323
/// Two `Constraint`s on the same sequence had different lengths. This is an error.
322
324
Contradiction ( String ) ,
@@ -360,7 +362,7 @@ impl LockstepIterSize {
360
362
/// multiple nested matcher sequences.
361
363
fn lockstep_iter_size (
362
364
tree : & mbe:: TokenTree ,
363
- interpolations : & FxHashMap < Ident , NamedMatch > ,
365
+ interpolations : & FxHashMap < LegacyIdent , NamedMatch > ,
364
366
repeats : & [ ( usize , usize ) ] ,
365
367
) -> LockstepIterSize {
366
368
use mbe:: TokenTree ;
@@ -376,6 +378,7 @@ fn lockstep_iter_size(
376
378
} )
377
379
}
378
380
TokenTree :: MetaVar ( _, name) | TokenTree :: MetaVarDecl ( _, name, _) => {
381
+ let name = LegacyIdent :: new ( name) ;
379
382
match lookup_cur_matched ( name, interpolations, repeats) {
380
383
Some ( matched) => match matched {
381
384
MatchedNonterminal ( _) => LockstepIterSize :: Unconstrained ,
0 commit comments