@@ -7,7 +7,7 @@ use crate::mbe::metavar_expr::{MetaVarExprConcatElem, RAW_IDENT_ERR};
7
7
use crate :: mbe:: { self , KleeneOp , MetaVarExpr } ;
8
8
use rustc_ast:: mut_visit:: { self , MutVisitor } ;
9
9
use rustc_ast:: token:: IdentIsRaw ;
10
- use rustc_ast:: token:: { self , Delimiter , Token , TokenKind } ;
10
+ use rustc_ast:: token:: { self , Delimiter , InvisibleOrigin , NonterminalKind , Token , TokenKind } ;
11
11
use rustc_ast:: tokenstream:: { DelimSpacing , DelimSpan , Spacing , TokenStream , TokenTree } ;
12
12
use rustc_data_structures:: fx:: FxHashMap ;
13
13
use rustc_errors:: { pluralize, Diag , DiagCtxtHandle , PResult } ;
@@ -248,7 +248,6 @@ pub(super) fn transcribe<'a>(
248
248
}
249
249
}
250
250
251
- // Replace the meta-var with the matched token tree from the invocation.
252
251
mbe:: TokenTree :: MetaVar ( mut sp, mut original_ident) => {
253
252
// Find the matched nonterminal from the macro invocation, and use it to replace
254
253
// the meta-var.
@@ -268,6 +267,19 @@ pub(super) fn transcribe<'a>(
268
267
// some of the unnecessary whitespace.
269
268
let ident = MacroRulesNormalizedIdent :: new ( original_ident) ;
270
269
if let Some ( cur_matched) = lookup_cur_matched ( ident, interp, & repeats) {
270
+ let mut mk_delimited = |nt_kind, stream| {
271
+ // Emit as a token stream within `Delimiter::Invisible` to maintain parsing
272
+ // priorities.
273
+ marker. visit_span ( & mut sp) ;
274
+ // Both the open delim and close delim get the same span, which covers the
275
+ // `$foo` in the decl macro RHS.
276
+ TokenTree :: Delimited (
277
+ DelimSpan :: from_single ( sp) ,
278
+ DelimSpacing :: new ( Spacing :: Alone , Spacing :: Alone ) ,
279
+ Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( nt_kind) ) ,
280
+ stream,
281
+ )
282
+ } ;
271
283
let tt = match cur_matched {
272
284
MatchedSingle ( ParseNtResult :: Tt ( tt) ) => {
273
285
// `tt`s are emitted into the output stream directly as "raw tokens",
@@ -284,6 +296,9 @@ pub(super) fn transcribe<'a>(
284
296
let kind = token:: NtLifetime ( * ident) ;
285
297
TokenTree :: token_alone ( kind, sp)
286
298
}
299
+ MatchedSingle ( ParseNtResult :: Vis ( ref vis) ) => {
300
+ mk_delimited ( NonterminalKind :: Vis , TokenStream :: from_ast ( vis) )
301
+ }
287
302
MatchedSingle ( ParseNtResult :: Nt ( nt) ) => {
288
303
// Other variables are emitted into the output stream as groups with
289
304
// `Delimiter::Invisible` to maintain parsing priorities.
0 commit comments