@@ -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_session:: parse:: ParseSess ;
@@ -180,6 +180,19 @@ impl TTMacroExpander for MacroRulesMacroExpander {
180180 }
181181}
182182
183+ struct MacroRulesDummyExpander ;
184+
185+ impl TTMacroExpander for MacroRulesDummyExpander {
186+ fn expand < ' cx > (
187+ & self ,
188+ _: & ' cx mut ExtCtxt < ' _ > ,
189+ sp : Span ,
190+ _: TokenStream ,
191+ ) -> Box < dyn MacResult + ' cx > {
192+ DummyResult :: any ( sp)
193+ }
194+ }
195+
183196fn trace_macros_note ( cx_expansions : & mut FxHashMap < Span , Vec < String > > , sp : Span , message : String ) {
184197 let sp = sp. macro_backtrace ( ) . last ( ) . map ( |trace| trace. call_site ) . unwrap_or ( sp) ;
185198 cx_expansions. entry ( sp) . or_default ( ) . push ( message) ;
@@ -362,6 +375,18 @@ pub fn compile_declarative_macro(
362375 def : & ast:: Item ,
363376 edition : Edition ,
364377) -> SyntaxExtension {
378+ let mk_syn_ext = |expander| {
379+ SyntaxExtension :: new (
380+ sess,
381+ SyntaxExtensionKind :: LegacyBang ( expander) ,
382+ def. span ,
383+ Vec :: new ( ) ,
384+ edition,
385+ def. ident . name ,
386+ & def. attrs ,
387+ )
388+ } ;
389+
365390 let diag = & sess. span_diagnostic ;
366391 let lhs_nm = ast:: Ident :: new ( sym:: lhs, def. span ) ;
367392 let rhs_nm = ast:: Ident :: new ( sym:: rhs, def. span ) ;
@@ -416,13 +441,12 @@ pub fn compile_declarative_macro(
416441 Failure ( token, msg) => {
417442 let s = parse_failure_msg ( & token) ;
418443 let sp = token. span . substitute_dummy ( def. span ) ;
419- let mut err = sess. span_diagnostic . struct_span_fatal ( sp, & s) ;
420- err. span_label ( sp, msg) ;
421- err. emit ( ) ;
422- FatalError . raise ( ) ;
444+ sess. span_diagnostic . struct_span_err ( sp, & s) . span_label ( sp, msg) . emit ( ) ;
445+ return mk_syn_ext ( Box :: new ( MacroRulesDummyExpander ) ) ;
423446 }
424- Error ( sp, s) => {
425- sess. span_diagnostic . span_fatal ( sp. substitute_dummy ( def. span ) , & s) . raise ( ) ;
447+ Error ( sp, msg) => {
448+ sess. span_diagnostic . struct_span_err ( sp. substitute_dummy ( def. span ) , & msg) . emit ( ) ;
449+ return mk_syn_ext ( Box :: new ( MacroRulesDummyExpander ) ) ;
426450 }
427451 } ;
428452
@@ -494,15 +518,7 @@ pub fn compile_declarative_macro(
494518 valid,
495519 } ) ;
496520
497- SyntaxExtension :: new (
498- sess,
499- SyntaxExtensionKind :: LegacyBang ( expander) ,
500- def. span ,
501- Vec :: new ( ) ,
502- edition,
503- def. ident . name ,
504- & def. attrs ,
505- )
521+ mk_syn_ext ( expander)
506522}
507523
508524fn check_lhs_nt_follows (
0 commit comments