self.parse_pat_with_range_pat(true, expected)
}
- /// Parses patterns, separated by '|' s.
- pub(super) fn parse_pats(&mut self) -> PResult<'a, Vec<P<Pat>>> {
- // Allow a '|' before the pats (RFCs 1925, 2530, and 2535).
- self.eat_or_separator();
-
- let mut pats = Vec::new();
- loop {
- pats.push(self.parse_top_level_pat()?);
+ // FIXME(or_patterns, Centril | dlrobertson):
+ // remove this and use `parse_top_pat` everywhere it is used instead.
+ pub(super) fn parse_top_pat_unpack(&mut self, gate_or: bool) -> PResult<'a, Vec<P<Pat>>> {
+ self.parse_top_pat(gate_or)
+ .map(|pat| pat.and_then(|pat| match pat.node {
+ PatKind::Or(pats) => pats,
+ node => vec![self.mk_pat(pat.span, node)],
+ }))
+ }
- if !self.eat_or_separator() {
- return Ok(pats);
- }
+ /// Entry point to the main pattern parser.
+ /// Corresponds to `top_pat` in RFC 2535 and allows or-pattern at the top level.
+ pub(super) fn parse_top_pat(&mut self, gate_or: bool) -> PResult<'a, P<Pat>> {
+ // Allow a '|' before the pats (RFCs 1925, 2530, and 2535).
+ if self.eat_or_separator() && gate_or {
+ self.sess.gated_spans.or_patterns.borrow_mut().push(self.prev_span);
}
+
+ self.parse_pat_with_or(None, gate_or, true)
}
pub(super) fn parse_top_level_pat(&mut self) -> PResult<'a, P<Pat>> {
}
}
+ /// We have parsed `||` instead of `|`. Error and suggest `|` instead.
fn ban_unexpected_or_or(&mut self) {
self.struct_span_err(self.token.span, "unexpected token `||` after pattern")
.span_suggestion(