Implement multiple patterns with |
in if let
and while let
This commit is contained in:
parent
063deba92e
commit
8640a51ff8
12 changed files with 231 additions and 128 deletions
|
@ -3226,7 +3226,7 @@ impl<'a> Parser<'a> {
|
|||
-> PResult<'a, P<Expr>> {
|
||||
let lo = self.prev_span;
|
||||
self.expect_keyword(keywords::Let)?;
|
||||
let pat = self.parse_pat()?;
|
||||
let pats = self.parse_pats()?;
|
||||
self.expect(&token::Eq)?;
|
||||
let expr = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?;
|
||||
let thn = self.parse_block()?;
|
||||
|
@ -3236,7 +3236,7 @@ impl<'a> Parser<'a> {
|
|||
} else {
|
||||
(thn.span, None)
|
||||
};
|
||||
Ok(self.mk_expr(lo.to(hi), ExprKind::IfLet(pat, expr, thn, els), attrs))
|
||||
Ok(self.mk_expr(lo.to(hi), ExprKind::IfLet(pats, expr, thn, els), attrs))
|
||||
}
|
||||
|
||||
// `move |args| expr`
|
||||
|
@ -3327,13 +3327,13 @@ impl<'a> Parser<'a> {
|
|||
span_lo: Span,
|
||||
mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
|
||||
self.expect_keyword(keywords::Let)?;
|
||||
let pat = self.parse_pat()?;
|
||||
let pats = self.parse_pats()?;
|
||||
self.expect(&token::Eq)?;
|
||||
let expr = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?;
|
||||
let (iattrs, body) = self.parse_inner_attrs_and_block()?;
|
||||
attrs.extend(iattrs);
|
||||
let span = span_lo.to(body.span);
|
||||
return Ok(self.mk_expr(span, ExprKind::WhileLet(pat, expr, body, opt_label), attrs));
|
||||
return Ok(self.mk_expr(span, ExprKind::WhileLet(pats, expr, body, opt_label), attrs));
|
||||
}
|
||||
|
||||
// parse `loop {...}`, `loop` token already eaten
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue