Rollup merge of #48490 - petrochenkov:orpat, r=eddyb
Implement multiple patterns with `|` in `if let` and `while let` (RFC 2175) cc https://github.com/rust-lang/rust/issues/48215
This commit is contained in:
commit
9523c82543
12 changed files with 231 additions and 128 deletions
|
@ -3228,7 +3228,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()?;
|
||||
|
@ -3238,7 +3238,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`
|
||||
|
@ -3329,13 +3329,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