diff options
| author | Caio <c410.f3r@gmail.com> | 2021-01-01 15:38:11 -0300 |
|---|---|---|
| committer | Caio <c410.f3r@gmail.com> | 2021-01-07 18:54:12 -0300 |
| commit | f85fc264fecf5ab8b16c152dde8a440055323424 (patch) | |
| tree | 835f4f3a86c2019c5ac18f65c4cfa5de7fd297a4 /compiler/rustc_passes/src | |
| parent | c8915eebeaaef9f7cc1cff6ffd97f578b03c2ac9 (diff) | |
| download | rust-f85fc264fecf5ab8b16c152dde8a440055323424.tar.gz rust-f85fc264fecf5ab8b16c152dde8a440055323424.zip | |
Reintroduce hir::ExprKind::If
Diffstat (limited to 'compiler/rustc_passes/src')
| -rw-r--r-- | compiler/rustc_passes/src/check_const.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/liveness.rs | 26 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/naked_functions.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/region.rs | 11 |
4 files changed, 38 insertions, 4 deletions
diff --git a/compiler/rustc_passes/src/check_const.rs b/compiler/rustc_passes/src/check_const.rs index 2d6bbff460d..c887a860303 100644 --- a/compiler/rustc_passes/src/check_const.rs +++ b/compiler/rustc_passes/src/check_const.rs @@ -49,9 +49,7 @@ impl NonConstExpr { // All other expressions are allowed. Self::Loop(Loop | While | WhileLet) - | Self::Match( - WhileDesugar | WhileLetDesugar | Normal | IfDesugar { .. } | IfLetDesugar { .. }, - ) => &[], + | Self::Match(WhileDesugar | WhileLetDesugar | Normal | IfLetDesugar { .. }) => &[], }; Some(gates) diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index fcea1b29ec3..6202cc312fc 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -419,7 +419,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> { } // live nodes required for interesting control flow: - hir::ExprKind::Match(..) | hir::ExprKind::Loop(..) => { + hir::ExprKind::If(..) | hir::ExprKind::Match(..) | hir::ExprKind::Loop(..) => { self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span)); intravisit::walk_expr(self, expr); } @@ -846,6 +846,29 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // at the label ident hir::ExprKind::Loop(ref blk, _, _) => self.propagate_through_loop(expr, &blk, succ), + hir::ExprKind::If(ref cond, ref then, ref else_opt) => { + // + // (cond) + // | + // v + // (expr) + // / \ + // | | + // v v + // (then)(els) + // | | + // v v + // ( succ ) + // + let else_ln = + self.propagate_through_opt_expr(else_opt.as_ref().map(|e| &**e), succ); + let then_ln = self.propagate_through_expr(&then, succ); + let ln = self.live_node(expr.hir_id, expr.span); + self.init_from_succ(ln, else_ln); + self.merge_from_succ(ln, then_ln); + self.propagate_through_expr(&cond, ln) + } + hir::ExprKind::Match(ref e, arms, _) => { // // (e) @@ -1336,6 +1359,7 @@ fn check_expr<'tcx>(this: &mut Liveness<'_, 'tcx>, expr: &'tcx Expr<'tcx>) { | hir::ExprKind::Tup(..) | hir::ExprKind::Binary(..) | hir::ExprKind::Cast(..) + | hir::ExprKind::If(..) | hir::ExprKind::DropTemps(..) | hir::ExprKind::Unary(..) | hir::ExprKind::Ret(..) diff --git a/compiler/rustc_passes/src/naked_functions.rs b/compiler/rustc_passes/src/naked_functions.rs index 788f1df328c..93fb23c018b 100644 --- a/compiler/rustc_passes/src/naked_functions.rs +++ b/compiler/rustc_passes/src/naked_functions.rs @@ -201,6 +201,7 @@ impl<'tcx> CheckInlineAssembly<'tcx> { | ExprKind::Type(..) | ExprKind::Loop(..) | ExprKind::Match(..) + | ExprKind::If(..) | ExprKind::Closure(..) | ExprKind::Assign(..) | ExprKind::AssignOp(..) diff --git a/compiler/rustc_passes/src/region.rs b/compiler/rustc_passes/src/region.rs index 1af79abe4b9..91421d7f5f2 100644 --- a/compiler/rustc_passes/src/region.rs +++ b/compiler/rustc_passes/src/region.rs @@ -241,6 +241,17 @@ 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); + 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); + terminating(then.hir_id.local_id); + } + hir::ExprKind::Loop(ref body, _, _) => { terminating(body.hir_id.local_id); } |
