parser: parse_pats -> parse_top_pat{_unpack}.
This commit is contained in:
@@ -1241,11 +1241,12 @@ impl<'a> Parser<'a> {
|
||||
Ok(cond)
|
||||
}
|
||||
|
||||
/// Parses a `let $pats = $expr` pseudo-expression.
|
||||
/// Parses a `let $pat = $expr` pseudo-expression.
|
||||
/// The `let` token has already been eaten.
|
||||
fn parse_let_expr(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
|
||||
let lo = self.prev_span;
|
||||
let pats = self.parse_pats()?;
|
||||
// FIXME(or_patterns, Centril | dlrobertson): use `parse_top_pat` instead.
|
||||
let pat = self.parse_top_pat_unpack(false)?;
|
||||
self.expect(&token::Eq)?;
|
||||
let expr = self.with_res(
|
||||
Restrictions::NO_STRUCT_LITERAL,
|
||||
@@ -1253,7 +1254,7 @@ impl<'a> Parser<'a> {
|
||||
)?;
|
||||
let span = lo.to(expr.span);
|
||||
self.sess.gated_spans.let_chains.borrow_mut().push(span);
|
||||
Ok(self.mk_expr(span, ExprKind::Let(pats, expr), attrs))
|
||||
Ok(self.mk_expr(span, ExprKind::Let(pat, expr), attrs))
|
||||
}
|
||||
|
||||
/// `else` token already eaten
|
||||
@@ -1387,7 +1388,8 @@ impl<'a> Parser<'a> {
|
||||
crate fn parse_arm(&mut self) -> PResult<'a, Arm> {
|
||||
let attrs = self.parse_outer_attributes()?;
|
||||
let lo = self.token.span;
|
||||
let pats = self.parse_pats()?;
|
||||
// FIXME(or_patterns, Centril | dlrobertson): use `parse_top_pat` instead.
|
||||
let pat = self.parse_top_pat_unpack(false)?;
|
||||
let guard = if self.eat_keyword(kw::If) {
|
||||
Some(self.parse_expr()?)
|
||||
} else {
|
||||
@@ -1448,7 +1450,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
Ok(ast::Arm {
|
||||
attrs,
|
||||
pats,
|
||||
pats: pat, // FIXME(or_patterns, Centril | dlrobertson): this should just be `pat,`.
|
||||
guard,
|
||||
body: expr,
|
||||
span: lo.to(hi),
|
||||
|
||||
@@ -20,19 +20,25 @@ impl<'a> Parser<'a> {
|
||||
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>>> {
|
||||
// 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)],
|
||||
}))
|
||||
}
|
||||
|
||||
/// 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).
|
||||
self.eat_or_separator();
|
||||
|
||||
let mut pats = Vec::new();
|
||||
loop {
|
||||
pats.push(self.parse_top_level_pat()?);
|
||||
|
||||
if !self.eat_or_separator() {
|
||||
return Ok(pats);
|
||||
}
|
||||
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>> {
|
||||
|
||||
Reference in New Issue
Block a user