diff options
| author | Caio <c410.f3r@gmail.com> | 2021-08-08 11:49:13 -0300 |
|---|---|---|
| committer | Caio <c410.f3r@gmail.com> | 2021-08-15 16:18:26 -0300 |
| commit | 6aa9937a768bf13e5f7bd0ee6dd8579403b39058 (patch) | |
| tree | ad4c8d3c2233b953d6088456650d26972c3d581b /compiler/rustc_passes | |
| parent | 2d9f2eae84dc3988c5463fdd1b124a9b695447d7 (diff) | |
| download | rust-6aa9937a768bf13e5f7bd0ee6dd8579403b39058.tar.gz rust-6aa9937a768bf13e5f7bd0ee6dd8579403b39058.zip | |
Introduce hir::ExprKind::Let - Take 2
Diffstat (limited to 'compiler/rustc_passes')
| -rw-r--r-- | compiler/rustc_passes/src/check_const.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/liveness.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/naked_functions.rs | 1 |
3 files changed, 18 insertions, 9 deletions
diff --git a/compiler/rustc_passes/src/check_const.rs b/compiler/rustc_passes/src/check_const.rs index f6a93f5e02d..4a82252a32b 100644 --- a/compiler/rustc_passes/src/check_const.rs +++ b/compiler/rustc_passes/src/check_const.rs @@ -48,11 +48,8 @@ impl NonConstExpr { Self::Match(TryDesugar) => &[sym::const_try], - Self::Match(IfLetGuardDesugar) => bug!("`if let` guard outside a `match` expression"), - // All other expressions are allowed. - Self::Loop(Loop | While | WhileLet) - | Self::Match(WhileDesugar | WhileLetDesugar | Normal | IfLetDesugar { .. }) => &[], + Self::Loop(Loop | While) | Self::Match(Normal) => &[], }; Some(gates) @@ -277,9 +274,7 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> { hir::ExprKind::Match(_, _, source) => { let non_const_expr = match source { // These are handled by `ExprKind::Loop` above. - hir::MatchSource::WhileDesugar - | hir::MatchSource::WhileLetDesugar - | hir::MatchSource::ForLoopDesugar => None, + hir::MatchSource::ForLoopDesugar => None, _ => Some(NonConstExpr::Match(*source)), }; diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index f2c2521ab43..2cd780e1b9b 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -429,6 +429,11 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> { intravisit::walk_expr(self, expr); } + hir::ExprKind::Let(ref pat, ..) => { + self.add_from_pat(pat); + intravisit::walk_expr(self, expr); + } + // live nodes required for interesting control flow: hir::ExprKind::If(..) | hir::ExprKind::Match(..) | hir::ExprKind::Loop(..) => { self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span)); @@ -852,6 +857,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { }) } + hir::ExprKind::Let(ref pat, ref scrutinee, _) => { + let succ = self.propagate_through_expr(scrutinee, succ); + self.define_bindings_in_pat(pat, succ) + } + // Note that labels have been resolved, so we don't need to look // at the label ident hir::ExprKind::Loop(ref blk, ..) => self.propagate_through_loop(expr, &blk, succ), @@ -1303,6 +1313,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Liveness<'a, 'tcx> { fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) { check_expr(self, ex); + intravisit::walk_expr(self, ex); } fn visit_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) { @@ -1358,6 +1369,10 @@ fn check_expr<'tcx>(this: &mut Liveness<'_, 'tcx>, expr: &'tcx Expr<'tcx>) { } } + hir::ExprKind::Let(ref pat, ..) => { + this.check_unused_vars_in_pat(pat, None, |_, _, _, _| {}); + } + // no correctness conditions related to liveness hir::ExprKind::Call(..) | hir::ExprKind::MethodCall(..) @@ -1388,8 +1403,6 @@ fn check_expr<'tcx>(this: &mut Liveness<'_, 'tcx>, expr: &'tcx Expr<'tcx>) { | hir::ExprKind::Type(..) | hir::ExprKind::Err => {} } - - intravisit::walk_expr(this, expr); } impl<'tcx> Liveness<'_, 'tcx> { diff --git a/compiler/rustc_passes/src/naked_functions.rs b/compiler/rustc_passes/src/naked_functions.rs index 899503cc556..d3ecd18a93c 100644 --- a/compiler/rustc_passes/src/naked_functions.rs +++ b/compiler/rustc_passes/src/naked_functions.rs @@ -221,6 +221,7 @@ impl<'tcx> CheckInlineAssembly<'tcx> { | ExprKind::Index(..) | ExprKind::Path(..) | ExprKind::AddrOf(..) + | ExprKind::Let(..) | ExprKind::Break(..) | ExprKind::Continue(..) | ExprKind::Ret(..) |
