@@ -485,7 +485,9 @@ pub fn compile_declarative_macro(
485
485
)
486
486
. pop ( )
487
487
. unwrap ( ) ;
488
- valid &= check_lhs_nt_follows ( sess, def, & tt) ;
488
+ // We don't handle errors here, the driver will abort
489
+ // after parsing/expansion. we can report every error in every macro this way.
490
+ valid &= check_lhs_nt_follows ( sess, def, & tt) . is_ok ( ) ;
489
491
return tt;
490
492
}
491
493
sess. dcx ( ) . span_bug ( def. span , "wrong-structured lhs" )
@@ -589,18 +591,19 @@ pub fn compile_declarative_macro(
589
591
( mk_syn_ext ( expander) , rule_spans)
590
592
}
591
593
592
- fn check_lhs_nt_follows ( sess : & Session , def : & ast:: Item , lhs : & mbe:: TokenTree ) -> bool {
594
+ fn check_lhs_nt_follows (
595
+ sess : & Session ,
596
+ def : & ast:: Item ,
597
+ lhs : & mbe:: TokenTree ,
598
+ ) -> Result < ( ) , ErrorGuaranteed > {
593
599
// lhs is going to be like TokenTree::Delimited(...), where the
594
600
// entire lhs is those tts. Or, it can be a "bare sequence", not wrapped in parens.
595
601
if let mbe:: TokenTree :: Delimited ( .., delimited) = lhs {
596
602
check_matcher ( sess, def, & delimited. tts )
597
603
} else {
598
604
let msg = "invalid macro matcher; matchers must be contained in balanced delimiters" ;
599
- sess. dcx ( ) . span_err ( lhs. span ( ) , msg) ;
600
- false
605
+ Err ( sess. dcx ( ) . span_err ( lhs. span ( ) , msg) )
601
606
}
602
- // we don't abort on errors on rejection, the driver will do that for us
603
- // after parsing/expansion. we can report every error in every macro this way.
604
607
}
605
608
606
609
fn is_empty_token_tree ( sess : & Session , seq : & mbe:: SequenceRepetition ) -> bool {
@@ -675,12 +678,15 @@ fn check_rhs(sess: &Session, rhs: &mbe::TokenTree) -> bool {
675
678
false
676
679
}
677
680
678
- fn check_matcher ( sess : & Session , def : & ast:: Item , matcher : & [ mbe:: TokenTree ] ) -> bool {
681
+ fn check_matcher (
682
+ sess : & Session ,
683
+ def : & ast:: Item ,
684
+ matcher : & [ mbe:: TokenTree ] ,
685
+ ) -> Result < ( ) , ErrorGuaranteed > {
679
686
let first_sets = FirstSets :: new ( matcher) ;
680
687
let empty_suffix = TokenSet :: empty ( ) ;
681
- let err = sess. dcx ( ) . err_count ( ) ;
682
- check_matcher_core ( sess, def, & first_sets, matcher, & empty_suffix) ;
683
- err == sess. dcx ( ) . err_count ( )
688
+ check_matcher_core ( sess, def, & first_sets, matcher, & empty_suffix) ?;
689
+ Ok ( ( ) )
684
690
}
685
691
686
692
fn has_compile_error_macro ( rhs : & mbe:: TokenTree ) -> bool {
@@ -1020,11 +1026,13 @@ fn check_matcher_core<'tt>(
1020
1026
first_sets : & FirstSets < ' tt > ,
1021
1027
matcher : & ' tt [ mbe:: TokenTree ] ,
1022
1028
follow : & TokenSet < ' tt > ,
1023
- ) -> TokenSet < ' tt > {
1029
+ ) -> Result < TokenSet < ' tt > , ErrorGuaranteed > {
1024
1030
use mbe:: TokenTree ;
1025
1031
1026
1032
let mut last = TokenSet :: empty ( ) ;
1027
1033
1034
+ let mut errored = Ok ( ( ) ) ;
1035
+
1028
1036
// 2. For each token and suffix [T, SUFFIX] in M:
1029
1037
// ensure that T can be followed by SUFFIX, and if SUFFIX may be empty,
1030
1038
// then ensure T can also be followed by any element of FOLLOW.
@@ -1068,7 +1076,7 @@ fn check_matcher_core<'tt>(
1068
1076
token:: CloseDelim ( d. delim ) ,
1069
1077
span. close ,
1070
1078
) ) ;
1071
- check_matcher_core ( sess, def, first_sets, & d. tts , & my_suffix) ;
1079
+ check_matcher_core ( sess, def, first_sets, & d. tts , & my_suffix) ? ;
1072
1080
// don't track non NT tokens
1073
1081
last. replace_with_irrelevant ( ) ;
1074
1082
@@ -1100,7 +1108,7 @@ fn check_matcher_core<'tt>(
1100
1108
// At this point, `suffix_first` is built, and
1101
1109
// `my_suffix` is some TokenSet that we can use
1102
1110
// for checking the interior of `seq_rep`.
1103
- let next = check_matcher_core ( sess, def, first_sets, & seq_rep. tts , my_suffix) ;
1111
+ let next = check_matcher_core ( sess, def, first_sets, & seq_rep. tts , my_suffix) ? ;
1104
1112
if next. maybe_empty {
1105
1113
last. add_all ( & next) ;
1106
1114
} else {
@@ -1206,14 +1214,15 @@ fn check_matcher_core<'tt>(
1206
1214
) ) ;
1207
1215
}
1208
1216
}
1209
- err. emit ( ) ;
1217
+ errored = Err ( err. emit ( ) ) ;
1210
1218
}
1211
1219
}
1212
1220
}
1213
1221
}
1214
1222
}
1215
1223
}
1216
- last
1224
+ errored?;
1225
+ Ok ( last)
1217
1226
}
1218
1227
1219
1228
fn token_can_be_followed_by_any ( tok : & mbe:: TokenTree ) -> bool {
0 commit comments