Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit bab2080

Browse files
Introduce if-let guards in the THIR
1 parent cfaaa21 commit bab2080

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,10 @@ impl ToBorrowKind for hir::Mutability {
776776
fn convert_arm<'tcx>(cx: &mut Cx<'_, 'tcx>, arm: &'tcx hir::Arm<'tcx>) -> Arm<'tcx> {
777777
Arm {
778778
pattern: cx.pattern_from_hir(&arm.pat),
779-
guard: match arm.guard {
780-
Some(hir::Guard::If(ref e)) => Some(Guard::If(e.to_ref())),
781-
_ => None,
782-
},
779+
guard: arm.guard.as_ref().map(|g| match g {
780+
hir::Guard::If(ref e) => Guard::If(e.to_ref()),
781+
hir::Guard::IfLet(ref pat, ref e) => Guard::IfLet(cx.pattern_from_hir(pat), e.to_ref())
782+
}),
783783
body: arm.body.to_ref(),
784784
lint_level: LintLevel::Explicit(arm.hir_id),
785785
scope: region::Scope { id: arm.hir_id.local_id, data: region::ScopeData::Node },

compiler/rustc_mir_build/src/thir/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ crate struct Arm<'tcx> {
344344
#[derive(Clone, Debug)]
345345
crate enum Guard<'tcx> {
346346
If(ExprRef<'tcx>),
347+
IfLet(Pat<'tcx>, ExprRef<'tcx>),
347348
}
348349

349350
#[derive(Copy, Clone, Debug)]

0 commit comments

Comments
 (0)