@@ -762,10 +762,7 @@ pub(super) fn parse_tt(
762762 Err ( mut err) => {
763763 err. span_label (
764764 span,
765- format ! (
766- "while parsing argument for this `{}` macro fragment" ,
767- kind
768- ) ,
765+ format ! ( "while parsing argument for this `{kind}` macro fragment" ) ,
769766 )
770767 . emit ( ) ;
771768 return ErrorReported ;
@@ -784,31 +781,45 @@ pub(super) fn parse_tt(
784781 ( _, _) => {
785782 // We need to call the black-box parser to get some nonterminal, but something is
786783 // wrong.
787- let nts = bb_items
788- . iter ( )
789- . map ( |item| match item. top_elts . get_tt ( item. idx ) {
790- TokenTree :: MetaVarDecl ( _, bind, Some ( kind) ) => {
791- format ! ( "{} ('{}')" , kind, bind)
792- }
793- _ => panic ! ( ) ,
794- } )
795- . collect :: < Vec < String > > ( )
796- . join ( " or " ) ;
797-
798- return Error (
784+ return bb_items_ambiguity_error (
785+ macro_name,
786+ next_items,
787+ bb_items,
799788 parser. token . span ,
800- format ! (
801- "local ambiguity when calling macro `{macro_name}`: multiple parsing options: {}" ,
802- match next_items. len( ) {
803- 0 => format!( "built-in NTs {}." , nts) ,
804- 1 => format!( "built-in NTs {} or 1 other option." , nts) ,
805- n => format!( "built-in NTs {} or {} other options." , nts, n) ,
806- }
807- ) ,
808789 ) ;
809790 }
810791 }
811792
812793 assert ! ( !cur_items. is_empty( ) ) ;
813794 }
814795}
796+
797+ fn bb_items_ambiguity_error < ' root , ' tt > (
798+ macro_name : Ident ,
799+ next_items : SmallVec < [ MatcherPosHandle < ' root , ' tt > ; 1 ] > ,
800+ bb_items : SmallVec < [ MatcherPosHandle < ' root , ' tt > ; 1 ] > ,
801+ token_span : rustc_span:: Span ,
802+ ) -> NamedParseResult {
803+ let nts = bb_items
804+ . iter ( )
805+ . map ( |item| match item. top_elts . get_tt ( item. idx ) {
806+ TokenTree :: MetaVarDecl ( _, bind, Some ( kind) ) => {
807+ format ! ( "{} ('{}')" , kind, bind)
808+ }
809+ _ => panic ! ( ) ,
810+ } )
811+ . collect :: < Vec < String > > ( )
812+ . join ( " or " ) ;
813+
814+ Error (
815+ token_span,
816+ format ! (
817+ "local ambiguity when calling macro `{macro_name}`: multiple parsing options: {}" ,
818+ match next_items. len( ) {
819+ 0 => format!( "built-in NTs {}." , nts) ,
820+ 1 => format!( "built-in NTs {} or 1 other option." , nts) ,
821+ n => format!( "built-in NTs {} or {} other options." , nts, n) ,
822+ }
823+ ) ,
824+ )
825+ }
0 commit comments