@@ -375,6 +375,11 @@ fn transcribe_metavar<'tx>(
375375 return Ok ( ( ) ) ;
376376 } ;
377377
378+ let MatchedSingle ( pnr) = cur_matched else {
379+ // We were unable to descend far enough. This is an error.
380+ return Err ( dcx. create_err ( MacroVarStillRepeating { span : sp, ident } ) ) ;
381+ } ;
382+
378383 // We wrap the tokens in invisible delimiters, unless they are already wrapped
379384 // in invisible delimiters with the same `MetaVarKind`. Because some proc
380385 // macros can't handle multiple layers of invisible delimiters of the same
@@ -404,33 +409,33 @@ fn transcribe_metavar<'tx>(
404409 )
405410 } ;
406411
407- let tt = match cur_matched {
408- MatchedSingle ( ParseNtResult :: Tt ( tt) ) => {
412+ let tt = match pnr {
413+ ParseNtResult :: Tt ( tt) => {
409414 // `tt`s are emitted into the output stream directly as "raw tokens",
410415 // without wrapping them into groups. Other variables are emitted into
411416 // the output stream as groups with `Delimiter::Invisible` to maintain
412417 // parsing priorities.
413418 maybe_use_metavar_location ( tscx. psess , & tscx. stack , sp, tt, & mut tscx. marker )
414419 }
415- MatchedSingle ( ParseNtResult :: Ident ( ident, is_raw) ) => {
420+ ParseNtResult :: Ident ( ident, is_raw) => {
416421 tscx. marker . mark_span ( & mut sp) ;
417422 with_metavar_spans ( |mspans| mspans. insert ( ident. span , sp) ) ;
418423 let kind = token:: NtIdent ( * ident, * is_raw) ;
419424 TokenTree :: token_alone ( kind, sp)
420425 }
421- MatchedSingle ( ParseNtResult :: Lifetime ( ident, is_raw) ) => {
426+ ParseNtResult :: Lifetime ( ident, is_raw) => {
422427 tscx. marker . mark_span ( & mut sp) ;
423428 with_metavar_spans ( |mspans| mspans. insert ( ident. span , sp) ) ;
424429 let kind = token:: NtLifetime ( * ident, * is_raw) ;
425430 TokenTree :: token_alone ( kind, sp)
426431 }
427- MatchedSingle ( ParseNtResult :: Item ( item) ) => {
432+ ParseNtResult :: Item ( item) => {
428433 mk_delimited ( item. span , MetaVarKind :: Item , TokenStream :: from_ast ( item) )
429434 }
430- MatchedSingle ( ParseNtResult :: Block ( block) ) => {
435+ ParseNtResult :: Block ( block) => {
431436 mk_delimited ( block. span , MetaVarKind :: Block , TokenStream :: from_ast ( block) )
432437 }
433- MatchedSingle ( ParseNtResult :: Stmt ( stmt) ) => {
438+ ParseNtResult :: Stmt ( stmt) => {
434439 let stream = if let StmtKind :: Empty = stmt. kind {
435440 // FIXME: Properly collect tokens for empty statements.
436441 TokenStream :: token_alone ( token:: Semi , stmt. span )
@@ -439,10 +444,10 @@ fn transcribe_metavar<'tx>(
439444 } ;
440445 mk_delimited ( stmt. span , MetaVarKind :: Stmt , stream)
441446 }
442- MatchedSingle ( ParseNtResult :: Pat ( pat, pat_kind) ) => {
447+ ParseNtResult :: Pat ( pat, pat_kind) => {
443448 mk_delimited ( pat. span , MetaVarKind :: Pat ( * pat_kind) , TokenStream :: from_ast ( pat) )
444449 }
445- MatchedSingle ( ParseNtResult :: Expr ( expr, kind) ) => {
450+ ParseNtResult :: Expr ( expr, kind) => {
446451 let ( can_begin_literal_maybe_minus, can_begin_string_literal) = match & expr. kind {
447452 ExprKind :: Lit ( _) => ( true , true ) ,
448453 ExprKind :: Unary ( UnOp :: Neg , e) if matches ! ( & e. kind, ExprKind :: Lit ( _) ) => {
@@ -460,31 +465,27 @@ fn transcribe_metavar<'tx>(
460465 TokenStream :: from_ast ( expr) ,
461466 )
462467 }
463- MatchedSingle ( ParseNtResult :: Literal ( lit) ) => {
468+ ParseNtResult :: Literal ( lit) => {
464469 mk_delimited ( lit. span , MetaVarKind :: Literal , TokenStream :: from_ast ( lit) )
465470 }
466- MatchedSingle ( ParseNtResult :: Ty ( ty) ) => {
471+ ParseNtResult :: Ty ( ty) => {
467472 let is_path = matches ! ( & ty. kind, TyKind :: Path ( None , _path) ) ;
468473 mk_delimited ( ty. span , MetaVarKind :: Ty { is_path } , TokenStream :: from_ast ( ty) )
469474 }
470- MatchedSingle ( ParseNtResult :: Meta ( attr_item) ) => {
475+ ParseNtResult :: Meta ( attr_item) => {
471476 let has_meta_form = attr_item. meta_kind ( ) . is_some ( ) ;
472477 mk_delimited (
473478 attr_item. span ( ) ,
474479 MetaVarKind :: Meta { has_meta_form } ,
475480 TokenStream :: from_ast ( attr_item) ,
476481 )
477482 }
478- MatchedSingle ( ParseNtResult :: Path ( path) ) => {
483+ ParseNtResult :: Path ( path) => {
479484 mk_delimited ( path. span , MetaVarKind :: Path , TokenStream :: from_ast ( path) )
480485 }
481- MatchedSingle ( ParseNtResult :: Vis ( vis) ) => {
486+ ParseNtResult :: Vis ( vis) => {
482487 mk_delimited ( vis. span , MetaVarKind :: Vis , TokenStream :: from_ast ( vis) )
483488 }
484- MatchedSeq ( ..) => {
485- // We were unable to descend far enough. This is an error.
486- return Err ( dcx. create_err ( MacroVarStillRepeating { span : sp, ident } ) ) ;
487- }
488489 } ;
489490
490491 tscx. result . push ( tt) ;
0 commit comments