diff options
| author | Matthew Jasper <mjjasper1@gmail.com> | 2021-02-25 22:37:22 +0000 |
|---|---|---|
| committer | Caio <c410.f3r@gmail.com> | 2021-08-15 16:05:25 -0300 |
| commit | 2d9f2eae84dc3988c5463fdd1b124a9b695447d7 (patch) | |
| tree | 373c546d14e21ad7e4315d367c145f7ae00739b2 /compiler/rustc_passes/src | |
| parent | c0490a2dbbb94f8244fb6a15ca5d33dc3fcd268a (diff) | |
| download | rust-2d9f2eae84dc3988c5463fdd1b124a9b695447d7.tar.gz rust-2d9f2eae84dc3988c5463fdd1b124a9b695447d7.zip | |
Use correct drop scopes for if expressions
Diffstat (limited to 'compiler/rustc_passes/src')
| -rw-r--r-- | compiler/rustc_passes/src/region.rs | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/compiler/rustc_passes/src/region.rs b/compiler/rustc_passes/src/region.rs index c133f1a0417..7403e51c734 100644 --- a/compiler/rustc_passes/src/region.rs +++ b/compiler/rustc_passes/src/region.rs @@ -233,14 +233,12 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h terminating(r.hir_id.local_id); } - hir::ExprKind::If(ref expr, ref then, Some(ref otherwise)) => { - terminating(expr.hir_id.local_id); + hir::ExprKind::If(_, ref then, Some(ref otherwise)) => { terminating(then.hir_id.local_id); terminating(otherwise.hir_id.local_id); } - hir::ExprKind::If(ref expr, ref then, None) => { - terminating(expr.hir_id.local_id); + hir::ExprKind::If(_, ref then, None) => { terminating(then.hir_id.local_id); } @@ -392,6 +390,24 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h } } + hir::ExprKind::If(ref cond, ref then, Some(ref otherwise)) => { + // FIXME(matthewjasper): ideally the scope we use here would only + // contain the condition and then expression. This works, but + // can result in some extra drop flags. + visitor.cx.var_parent = visitor.cx.parent; + visitor.visit_expr(cond); + visitor.cx.var_parent = prev_cx.var_parent; + visitor.visit_expr(then); + visitor.visit_expr(otherwise); + } + + hir::ExprKind::If(ref cond, ref then, None) => { + visitor.cx.var_parent = visitor.cx.parent; + visitor.visit_expr(cond); + visitor.cx.var_parent = prev_cx.var_parent; + visitor.visit_expr(then); + } + _ => intravisit::walk_expr(visitor, expr), } |
