@@ -84,41 +84,56 @@ fn suggest_slice_pat(e: &mut DiagnosticBuilder<'_>, site_span: Span, parser: &Pa
8484 ) ;
8585}
8686
87+ fn emit_frag_parse_err (
88+ mut e : DiagnosticBuilder < ' _ > ,
89+ parser : & Parser < ' _ > ,
90+ site_span : Span ,
91+ macro_ident : ast:: Ident ,
92+ arm_span : Span ,
93+ kind : AstFragmentKind ,
94+ ) {
95+ if parser. token == token:: Eof && e. message ( ) . ends_with ( ", found `<eof>`" ) {
96+ if !e. span . is_dummy ( ) {
97+ // early end of macro arm (#52866)
98+ e. replace_span_with ( parser. sess . source_map ( ) . next_point ( parser. token . span ) ) ;
99+ }
100+ let msg = & e. message [ 0 ] ;
101+ e. message [ 0 ] = (
102+ format ! (
103+ "macro expansion ends with an incomplete expression: {}" ,
104+ msg. 0 . replace( ", found `<eof>`" , "" ) ,
105+ ) ,
106+ msg. 1 ,
107+ ) ;
108+ }
109+ if e. span . is_dummy ( ) {
110+ // Get around lack of span in error (#30128)
111+ e. replace_span_with ( site_span) ;
112+ if !parser. sess . source_map ( ) . is_imported ( arm_span) {
113+ e. span_label ( arm_span, "in this macro arm" ) ;
114+ }
115+ } else if parser. sess . source_map ( ) . is_imported ( parser. token . span ) {
116+ e. span_label ( site_span, "in this macro invocation" ) ;
117+ }
118+ match kind {
119+ AstFragmentKind :: Pat if macro_ident. name == sym:: vec => {
120+ suggest_slice_pat ( & mut e, site_span, parser) ;
121+ }
122+ _ => annotate_err_with_kind ( & mut e, kind, site_span) ,
123+ } ;
124+ e. emit ( ) ;
125+ }
126+
87127impl < ' a > ParserAnyMacro < ' a > {
88128 crate fn make ( mut self : Box < ParserAnyMacro < ' a > > , kind : AstFragmentKind ) -> AstFragment {
89129 let ParserAnyMacro { site_span, macro_ident, ref mut parser, arm_span } = * self ;
90- let fragment = panictry ! ( parse_ast_fragment( parser, kind) . map_err( |mut e| {
91- if parser. token == token:: Eof && e. message( ) . ends_with( ", found `<eof>`" ) {
92- if !e. span. is_dummy( ) {
93- // early end of macro arm (#52866)
94- e. replace_span_with( parser. sess. source_map( ) . next_point( parser. token. span) ) ;
95- }
96- let msg = & e. message[ 0 ] ;
97- e. message[ 0 ] = (
98- format!(
99- "macro expansion ends with an incomplete expression: {}" ,
100- msg. 0 . replace( ", found `<eof>`" , "" ) ,
101- ) ,
102- msg. 1 ,
103- ) ;
130+ let fragment = match parse_ast_fragment ( parser, kind) {
131+ Ok ( f) => f,
132+ Err ( err) => {
133+ emit_frag_parse_err ( err, parser, site_span, macro_ident, arm_span, kind) ;
134+ return kind. dummy ( site_span) ;
104135 }
105- if e. span. is_dummy( ) {
106- // Get around lack of span in error (#30128)
107- e. replace_span_with( site_span) ;
108- if !parser. sess. source_map( ) . is_imported( arm_span) {
109- e. span_label( arm_span, "in this macro arm" ) ;
110- }
111- } else if parser. sess. source_map( ) . is_imported( parser. token. span) {
112- e. span_label( site_span, "in this macro invocation" ) ;
113- }
114- match kind {
115- AstFragmentKind :: Pat if macro_ident. name == sym:: vec => {
116- suggest_slice_pat( & mut e, site_span, parser) ;
117- }
118- _ => annotate_err_with_kind( & mut e, kind, site_span) ,
119- } ;
120- e
121- } ) ) ;
136+ } ;
122137
123138 // We allow semicolons at the end of expressions -- e.g., the semicolon in
124139 // `macro_rules! m { () => { panic!(); } }` isn't parsed by `.parse_expr()`,
0 commit comments