@@ -15,7 +15,7 @@ use rustc_ast_pretty::pprust;
1515use rustc_attr:: { self as attr, TransparencyError } ;
1616use rustc_data_structures:: fx:: FxHashMap ;
1717use rustc_data_structures:: sync:: Lrc ;
18- use rustc_errors:: { Applicability , DiagnosticBuilder , FatalError } ;
18+ use rustc_errors:: { Applicability , DiagnosticBuilder } ;
1919use rustc_feature:: Features ;
2020use rustc_parse:: parser:: Parser ;
2121use rustc_parse:: Directory ;
@@ -181,6 +181,19 @@ impl TTMacroExpander for MacroRulesMacroExpander {
181181 }
182182}
183183
184+ struct MacroRulesDummyExpander ;
185+
186+ impl TTMacroExpander for MacroRulesDummyExpander {
187+ fn expand < ' cx > (
188+ & self ,
189+ _: & ' cx mut ExtCtxt < ' _ > ,
190+ sp : Span ,
191+ _: TokenStream ,
192+ ) -> Box < dyn MacResult + ' cx > {
193+ DummyResult :: any ( sp)
194+ }
195+ }
196+
184197fn trace_macros_note ( cx_expansions : & mut FxHashMap < Span , Vec < String > > , sp : Span , message : String ) {
185198 let sp = sp. macro_backtrace ( ) . last ( ) . map ( |trace| trace. call_site ) . unwrap_or ( sp) ;
186199 cx_expansions. entry ( sp) . or_default ( ) . push ( message) ;
@@ -369,6 +382,18 @@ pub fn compile_declarative_macro(
369382 def : & ast:: Item ,
370383 edition : Edition ,
371384) -> SyntaxExtension {
385+ let mk_syn_ext = |expander| {
386+ SyntaxExtension :: new (
387+ sess,
388+ SyntaxExtensionKind :: LegacyBang ( expander) ,
389+ def. span ,
390+ Vec :: new ( ) ,
391+ edition,
392+ def. ident . name ,
393+ & def. attrs ,
394+ )
395+ } ;
396+
372397 let diag = & sess. span_diagnostic ;
373398 let lhs_nm = ast:: Ident :: new ( sym:: lhs, def. span ) ;
374399 let rhs_nm = ast:: Ident :: new ( sym:: rhs, def. span ) ;
@@ -423,13 +448,12 @@ pub fn compile_declarative_macro(
423448 Failure ( token, msg) => {
424449 let s = parse_failure_msg ( & token) ;
425450 let sp = token. span . substitute_dummy ( def. span ) ;
426- let mut err = sess. span_diagnostic . struct_span_fatal ( sp, & s) ;
427- err. span_label ( sp, msg) ;
428- err. emit ( ) ;
429- FatalError . raise ( ) ;
451+ sess. span_diagnostic . struct_span_err ( sp, & s) . span_label ( sp, msg) . emit ( ) ;
452+ return mk_syn_ext ( Box :: new ( MacroRulesDummyExpander ) ) ;
430453 }
431- Error ( sp, s) => {
432- sess. span_diagnostic . span_fatal ( sp. substitute_dummy ( def. span ) , & s) . raise ( ) ;
454+ Error ( sp, msg) => {
455+ sess. span_diagnostic . struct_span_err ( sp. substitute_dummy ( def. span ) , & msg) . emit ( ) ;
456+ return mk_syn_ext ( Box :: new ( MacroRulesDummyExpander ) ) ;
433457 }
434458 } ;
435459
@@ -501,15 +525,7 @@ pub fn compile_declarative_macro(
501525 valid,
502526 } ) ;
503527
504- SyntaxExtension :: new (
505- sess,
506- SyntaxExtensionKind :: LegacyBang ( expander) ,
507- def. span ,
508- Vec :: new ( ) ,
509- edition,
510- def. ident . name ,
511- & def. attrs ,
512- )
528+ mk_syn_ext ( expander)
513529}
514530
515531fn check_lhs_nt_follows (
0 commit comments