Skip to content

Commit 6f83cd3

Browse files
committed
Recover expressions after tuple and paren patterns
1 parent 2176200 commit 6f83cd3

File tree

1 file changed

+12
-6
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+12
-6
lines changed

compiler/rustc_parse/src/parser/pat.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,8 @@ impl<'a> Parser<'a> {
714714
// For backward compatibility, `(..)` is a tuple pattern as well.
715715
let paren_pattern =
716716
fields.len() == 1 && !(matches!(trailing_comma, Trailing::Yes) || fields[0].is_rest());
717-
if paren_pattern {
717+
718+
let pat = if paren_pattern {
718719
let pat = fields.into_iter().next().unwrap();
719720
let close_paren = self.prev_token.span;
720721

@@ -732,7 +733,7 @@ impl<'a> Parser<'a> {
732733
},
733734
});
734735

735-
self.parse_pat_range_begin_with(begin.clone(), form)
736+
self.parse_pat_range_begin_with(begin.clone(), form)?
736737
}
737738
// recover ranges with parentheses around the `(start)..`
738739
PatKind::Err(guar)
@@ -747,15 +748,20 @@ impl<'a> Parser<'a> {
747748
},
748749
});
749750

750-
self.parse_pat_range_begin_with(self.mk_expr_err(pat.span, *guar), form)
751+
self.parse_pat_range_begin_with(self.mk_expr_err(pat.span, *guar), form)?
751752
}
752753

753754
// (pat) with optional parentheses
754-
_ => Ok(PatKind::Paren(pat)),
755+
_ => PatKind::Paren(pat),
755756
}
756757
} else {
757-
Ok(PatKind::Tuple(fields))
758-
}
758+
PatKind::Tuple(fields)
759+
};
760+
761+
Ok(match self.maybe_recover_trailing_expr(open_paren.to(self.prev_token.span), false) {
762+
None => pat,
763+
Some(guar) => PatKind::Err(guar)
764+
})
759765
}
760766

761767
/// Parse a mutable binding with the `mut` token already eaten.

0 commit comments

Comments
 (0)