@@ -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_parse:: Directory ;
@@ -181,6 +181,19 @@ impl TTMacroExpander for MacroRulesMacroExpander {
181
181
}
182
182
}
183
183
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
+
184
197
fn trace_macros_note ( cx_expansions : & mut FxHashMap < Span , Vec < String > > , sp : Span , message : String ) {
185
198
let sp = sp. macro_backtrace ( ) . last ( ) . map ( |trace| trace. call_site ) . unwrap_or ( sp) ;
186
199
cx_expansions. entry ( sp) . or_default ( ) . push ( message) ;
@@ -369,6 +382,18 @@ pub fn compile_declarative_macro(
369
382
def : & ast:: Item ,
370
383
edition : Edition ,
371
384
) -> 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
+
372
397
let diag = & sess. span_diagnostic ;
373
398
let lhs_nm = ast:: Ident :: new ( sym:: lhs, def. span ) ;
374
399
let rhs_nm = ast:: Ident :: new ( sym:: rhs, def. span ) ;
@@ -423,13 +448,12 @@ pub fn compile_declarative_macro(
423
448
Failure ( token, msg) => {
424
449
let s = parse_failure_msg ( & token) ;
425
450
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 ) ) ;
430
453
}
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 ) ) ;
433
457
}
434
458
} ;
435
459
@@ -501,15 +525,7 @@ pub fn compile_declarative_macro(
501
525
valid,
502
526
} ) ;
503
527
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)
513
529
}
514
530
515
531
fn check_lhs_nt_follows (
0 commit comments