Allow stuct literals in if let guards
This is consistent with normal match guards.
This commit is contained in:
parent
56c17dc280
commit
89235fd837
@ -2477,9 +2477,7 @@ fn parse_expr_let(&mut self) -> PResult<'a, P<Expr>> {
|
|||||||
} else {
|
} else {
|
||||||
self.expect(&token::Eq)?;
|
self.expect(&token::Eq)?;
|
||||||
}
|
}
|
||||||
let expr = self.with_res(self.restrictions | Restrictions::NO_STRUCT_LITERAL, |this| {
|
let expr = self.parse_expr_assoc_with(1 + prec_let_scrutinee_needs_par(), None.into())?;
|
||||||
this.parse_expr_assoc_with(1 + prec_let_scrutinee_needs_par(), None.into())
|
|
||||||
})?;
|
|
||||||
let span = lo.to(expr.span);
|
let span = lo.to(expr.span);
|
||||||
self.sess.gated_spans.gate(sym::let_chains, span);
|
self.sess.gated_spans.gate(sym::let_chains, span);
|
||||||
Ok(self.mk_expr(span, ExprKind::Let(pat, expr, span)))
|
Ok(self.mk_expr(span, ExprKind::Let(pat, expr, span)))
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
// Unlike `if` condition, `match` guards accept struct literals.
|
// Unlike `if` condition, `match` guards accept struct literals.
|
||||||
// This is detected in <https://github.com/rust-lang/rust/pull/74566#issuecomment-663613705>.
|
// This is detected in <https://github.com/rust-lang/rust/pull/74566#issuecomment-663613705>.
|
||||||
|
|
||||||
|
#![feature(if_let_guard)]
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
struct Foo {
|
struct Foo {
|
||||||
x: isize,
|
x: isize,
|
||||||
@ -11,6 +13,7 @@ struct Foo {
|
|||||||
fn foo(f: Foo) {
|
fn foo(f: Foo) {
|
||||||
match () {
|
match () {
|
||||||
() if f == Foo { x: 42 } => {}
|
() if f == Foo { x: 42 } => {}
|
||||||
|
() if let Foo { x: 0.. } = Foo { x: 42 } => {}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user