@@ -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) ;
@@ -364,6 +377,18 @@ pub fn compile_declarative_macro(
364
377
def : & ast:: Item ,
365
378
edition : Edition ,
366
379
) -> SyntaxExtension {
380
+ let mk_syn_ext = |expander| {
381
+ SyntaxExtension :: new (
382
+ sess,
383
+ SyntaxExtensionKind :: LegacyBang ( expander) ,
384
+ def. span ,
385
+ Vec :: new ( ) ,
386
+ edition,
387
+ def. ident . name ,
388
+ & def. attrs ,
389
+ )
390
+ } ;
391
+
367
392
let diag = & sess. span_diagnostic ;
368
393
let lhs_nm = ast:: Ident :: new ( sym:: lhs, def. span ) ;
369
394
let rhs_nm = ast:: Ident :: new ( sym:: rhs, def. span ) ;
@@ -418,13 +443,12 @@ pub fn compile_declarative_macro(
418
443
Failure ( token, msg) => {
419
444
let s = parse_failure_msg ( & token) ;
420
445
let sp = token. span . substitute_dummy ( def. span ) ;
421
- let mut err = sess. span_diagnostic . struct_span_fatal ( sp, & s) ;
422
- err. span_label ( sp, msg) ;
423
- err. emit ( ) ;
424
- FatalError . raise ( ) ;
446
+ sess. span_diagnostic . struct_span_err ( sp, & s) . span_label ( sp, msg) . emit ( ) ;
447
+ return mk_syn_ext ( Box :: new ( MacroRulesDummyExpander ) ) ;
425
448
}
426
- Error ( sp, s) => {
427
- sess. span_diagnostic . span_fatal ( sp. substitute_dummy ( def. span ) , & s) . raise ( ) ;
449
+ Error ( sp, msg) => {
450
+ sess. span_diagnostic . struct_span_err ( sp. substitute_dummy ( def. span ) , & msg) . emit ( ) ;
451
+ return mk_syn_ext ( Box :: new ( MacroRulesDummyExpander ) ) ;
428
452
}
429
453
} ;
430
454
@@ -496,15 +520,7 @@ pub fn compile_declarative_macro(
496
520
valid,
497
521
} ) ;
498
522
499
- SyntaxExtension :: new (
500
- sess,
501
- SyntaxExtensionKind :: LegacyBang ( expander) ,
502
- def. span ,
503
- Vec :: new ( ) ,
504
- edition,
505
- def. ident . name ,
506
- & def. attrs ,
507
- )
523
+ mk_syn_ext ( expander)
508
524
}
509
525
510
526
fn check_lhs_nt_follows (
0 commit comments