@@ -401,13 +401,7 @@ pub fn compile_declarative_macro(
401
401
if let Err ( e) = p. expect ( exp ! ( FatArrow ) ) {
402
402
return dummy_syn_ext ( e. emit ( ) ) ;
403
403
}
404
- if p. token == token:: Eof {
405
- let err_sp = p. token . span . shrink_to_hi ( ) ;
406
- let guar = sess
407
- . dcx ( )
408
- . struct_span_err ( err_sp, "macro definition ended unexpectedly" )
409
- . with_span_label ( err_sp, "expected right-hand side of macro rule" )
410
- . emit ( ) ;
404
+ if let Some ( guar) = check_no_eof ( sess, & p, "expected right-hand side of macro rule" ) {
411
405
return dummy_syn_ext ( guar) ;
412
406
}
413
407
let rhs_tt = p. parse_token_tree ( ) ;
@@ -453,6 +447,19 @@ pub fn compile_declarative_macro(
453
447
( mk_syn_ext ( expander) , nrules)
454
448
}
455
449
450
+ fn check_no_eof ( sess : & Session , p : & Parser < ' _ > , msg : & ' static str ) -> Option < ErrorGuaranteed > {
451
+ if p. token == token:: Eof {
452
+ let err_sp = p. token . span . shrink_to_hi ( ) ;
453
+ let guar = sess
454
+ . dcx ( )
455
+ . struct_span_err ( err_sp, "macro definition ended unexpectedly" )
456
+ . with_span_label ( err_sp, msg)
457
+ . emit ( ) ;
458
+ return Some ( guar) ;
459
+ }
460
+ None
461
+ }
462
+
456
463
fn check_lhs ( sess : & Session , node_id : NodeId , lhs : & mbe:: TokenTree ) -> Result < ( ) , ErrorGuaranteed > {
457
464
let e1 = check_lhs_nt_follows ( sess, node_id, lhs) ;
458
465
let e2 = check_lhs_no_empty_seq ( sess, slice:: from_ref ( lhs) ) ;
0 commit comments