let-else: add hir::Let and type check it like a hir::Local
unify typeck of hir::Local and hir::Let remove extraneous pub(crate/super)
This commit is contained in:
parent
a0a4c7d1e4
commit
af2f0e6b7c
13 changed files with 160 additions and 92 deletions
|
@ -605,9 +605,10 @@ impl<'tcx> Cx<'tcx> {
|
|||
},
|
||||
Err(err) => bug!("invalid loop id for continue: {}", err),
|
||||
},
|
||||
hir::ExprKind::Let(ref pat, ref expr, _) => {
|
||||
ExprKind::Let { expr: self.mirror_expr(expr), pat: self.pattern_from_hir(pat) }
|
||||
}
|
||||
hir::ExprKind::Let(let_expr) => ExprKind::Let {
|
||||
expr: self.mirror_expr(let_expr.init),
|
||||
pat: self.pattern_from_hir(let_expr.pat),
|
||||
},
|
||||
hir::ExprKind::If(cond, then, else_opt) => ExprKind::If {
|
||||
if_then_scope: region::Scope {
|
||||
id: then.hir_id.local_id,
|
||||
|
|
|
@ -64,7 +64,9 @@ impl<'tcx> Visitor<'tcx> for MatchVisitor<'_, '_, 'tcx> {
|
|||
intravisit::walk_expr(self, ex);
|
||||
match &ex.kind {
|
||||
hir::ExprKind::Match(scrut, arms, source) => self.check_match(scrut, arms, *source),
|
||||
hir::ExprKind::Let(pat, scrut, span) => self.check_let(pat, scrut, *span),
|
||||
hir::ExprKind::Let(hir::Let { pat, init, span, .. }) => {
|
||||
self.check_let(pat, init, *span)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -148,9 +150,9 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_let(&mut self, pat: &'tcx hir::Pat<'tcx>, expr: &hir::Expr<'_>, span: Span) {
|
||||
fn check_let(&mut self, pat: &'tcx hir::Pat<'tcx>, scrutinee: &hir::Expr<'_>, span: Span) {
|
||||
self.check_patterns(pat, Refutable);
|
||||
let mut cx = self.new_cx(expr.hir_id);
|
||||
let mut cx = self.new_cx(scrutinee.hir_id);
|
||||
let tpat = self.lower_pattern(&mut cx, pat, &mut false);
|
||||
check_let_reachability(&mut cx, pat.hir_id, tpat, span);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue