diff options
| author | LeSeulArtichaut <leseulartichaut@gmail.com> | 2020-10-24 21:13:54 +0200 |
|---|---|---|
| committer | LeSeulArtichaut <leseulartichaut@gmail.com> | 2020-12-06 11:48:06 +0100 |
| commit | 77d80b22f1abe8392f7124fec343fdbbe760340e (patch) | |
| tree | 4696c37062c68fdcc843dda095c4c06a5a188637 /compiler/rustc_ast_lowering/src/expr.rs | |
| parent | a68864b68859e5848865bd392ce6d892b16f5cdd (diff) | |
| download | rust-77d80b22f1abe8392f7124fec343fdbbe760340e.tar.gz rust-77d80b22f1abe8392f7124fec343fdbbe760340e.zip | |
Introduce if-let guards in the HIR
Diffstat (limited to 'compiler/rustc_ast_lowering/src/expr.rs')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index e0e78a4d609..7c95c7f6480 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -505,14 +505,19 @@ impl<'hir> LoweringContext<'_, 'hir> { } fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> { + let pat = self.lower_pat(&arm.pat); + let guard = arm.guard.as_ref().map(|cond| { + if let ExprKind::Let(ref pat, ref scrutinee) = cond.kind { + hir::Guard::IfLet(self.lower_pat(pat), self.lower_expr(scrutinee)) + } else { + hir::Guard::If(self.lower_expr(cond)) + } + }); hir::Arm { hir_id: self.next_id(), attrs: self.lower_attrs(&arm.attrs), - pat: self.lower_pat(&arm.pat), - guard: match arm.guard { - Some(ref x) => Some(hir::Guard::If(self.lower_expr(x))), - _ => None, - }, + pat, + guard, body: self.lower_expr(&arm.body), span: arm.span, } |
