@@ -2718,13 +2718,12 @@ impl<'a> Parser<'a> {
2718
2718
) ) ;
2719
2719
}
2720
2720
this. expect_one_of ( & [ token:: Comma ] , & [ token:: CloseDelim ( Delimiter :: Brace ) ] )
2721
- . map_err ( |mut err| {
2722
- match ( sm. span_to_lines ( expr. span ) , sm. span_to_lines ( arm_start_span) ) {
2723
- ( Ok ( ref expr_lines) , Ok ( ref arm_start_lines) )
2724
- if arm_start_lines. lines [ 0 ] . end_col
2725
- == expr_lines. lines [ 0 ] . end_col
2726
- && expr_lines. lines . len ( ) == 2
2727
- && this. token == token:: FatArrow =>
2721
+ . or_else ( |mut err| {
2722
+ if this. token == token:: FatArrow {
2723
+ if let Ok ( expr_lines) = sm. span_to_lines ( expr. span )
2724
+ && let Ok ( arm_start_lines) = sm. span_to_lines ( arm_start_span)
2725
+ && arm_start_lines. lines [ 0 ] . end_col == expr_lines. lines [ 0 ] . end_col
2726
+ && expr_lines. lines . len ( ) == 2
2728
2727
{
2729
2728
// We check whether there's any trailing code in the parse span,
2730
2729
// if there isn't, we very likely have the following:
@@ -2743,15 +2742,41 @@ impl<'a> Parser<'a> {
2743
2742
"," . to_owned ( ) ,
2744
2743
Applicability :: MachineApplicable ,
2745
2744
) ;
2745
+ return Err ( err) ;
2746
2746
}
2747
- _ => {
2748
- err. span_label (
2749
- arrow_span,
2750
- "while parsing the `match` arm starting here" ,
2751
- ) ;
2747
+ } else {
2748
+ // FIXME(compiler-errors): We could also recover `; PAT =>` here
2749
+
2750
+ // Try to parse a following `PAT =>`, if successful
2751
+ // then we should recover.
2752
+ let mut snapshot = this. create_snapshot_for_diagnostic ( ) ;
2753
+ let pattern_follows = snapshot
2754
+ . parse_pat_allow_top_alt (
2755
+ None ,
2756
+ RecoverComma :: Yes ,
2757
+ RecoverColon :: Yes ,
2758
+ CommaRecoveryMode :: EitherTupleOrPipe ,
2759
+ )
2760
+ . map_err ( |err| err. cancel ( ) )
2761
+ . is_ok ( ) ;
2762
+ if pattern_follows && snapshot. check ( & TokenKind :: FatArrow ) {
2763
+ err. cancel ( ) ;
2764
+ this. struct_span_err (
2765
+ hi. shrink_to_hi ( ) ,
2766
+ "expected `,` following `match` arm" ,
2767
+ )
2768
+ . span_suggestion (
2769
+ hi. shrink_to_hi ( ) ,
2770
+ "missing a comma here to end this `match` arm" ,
2771
+ "," . to_owned ( ) ,
2772
+ Applicability :: MachineApplicable ,
2773
+ )
2774
+ . emit ( ) ;
2775
+ return Ok ( true ) ;
2752
2776
}
2753
2777
}
2754
- err
2778
+ err. span_label ( arrow_span, "while parsing the `match` arm starting here" ) ;
2779
+ Err ( err)
2755
2780
} ) ?;
2756
2781
} else {
2757
2782
this. eat ( & token:: Comma ) ;
0 commit comments