Introduce hir::ExprKind::Let - Take 2

This commit is contained in:
Caio 2021-08-08 11:49:13 -03:00
parent 2d9f2eae84
commit 6aa9937a76
128 changed files with 2080 additions and 2196 deletions

View file

@ -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)),
};

View file

@ -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> {

View file

@ -221,6 +221,7 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
| ExprKind::Index(..)
| ExprKind::Path(..)
| ExprKind::AddrOf(..)
| ExprKind::Let(..)
| ExprKind::Break(..)
| ExprKind::Continue(..)
| ExprKind::Ret(..)