@@ -15,7 +15,7 @@ use rustc_ast_pretty::pprust;
15
15
use rustc_attr:: { self as attr, TransparencyError } ;
16
16
use rustc_data_structures:: fx:: FxHashMap ;
17
17
use rustc_data_structures:: sync:: Lrc ;
18
- use rustc_errors:: { Applicability , DiagnosticBuilder , FatalError } ;
18
+ use rustc_errors:: { Applicability , DiagnosticBuilder } ;
19
19
use rustc_feature:: Features ;
20
20
use rustc_parse:: parser:: Parser ;
21
21
use rustc_session:: parse:: ParseSess ;
@@ -180,6 +180,19 @@ impl TTMacroExpander for MacroRulesMacroExpander {
180
180
}
181
181
}
182
182
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
+
183
196
fn trace_macros_note ( cx_expansions : & mut FxHashMap < Span , Vec < String > > , sp : Span , message : String ) {
184
197
let sp = sp. macro_backtrace ( ) . last ( ) . map ( |trace| trace. call_site ) . unwrap_or ( sp) ;
185
198
cx_expansions. entry ( sp) . or_default ( ) . push ( message) ;
@@ -362,6 +375,18 @@ pub fn compile_declarative_macro(
362
375
def : & ast:: Item ,
363
376
edition : Edition ,
364
377
) -> 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
+
365
390
let diag = & sess. span_diagnostic ;
366
391
let lhs_nm = ast:: Ident :: new ( sym:: lhs, def. span ) ;
367
392
let rhs_nm = ast:: Ident :: new ( sym:: rhs, def. span ) ;
@@ -416,13 +441,12 @@ pub fn compile_declarative_macro(
416
441
Failure ( token, msg) => {
417
442
let s = parse_failure_msg ( & token) ;
418
443
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 ) ) ;
423
446
}
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 ) ) ;
426
450
}
427
451
} ;
428
452
@@ -494,15 +518,7 @@ pub fn compile_declarative_macro(
494
518
valid,
495
519
} ) ;
496
520
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)
506
522
}
507
523
508
524
fn check_lhs_nt_follows (
0 commit comments