diff options
Diffstat (limited to 'crates/hir_ty/src/infer/expr.rs')
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 4e4f6e5a4..c3a5b979f 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -367,7 +367,7 @@ impl<'a> InferenceContext<'a> { | |||
367 | Expr::Path(p) => { | 367 | Expr::Path(p) => { |
368 | // FIXME this could be more efficient... | 368 | // FIXME this could be more efficient... |
369 | let resolver = resolver_for_expr(self.db.upcast(), self.owner, tgt_expr); | 369 | let resolver = resolver_for_expr(self.db.upcast(), self.owner, tgt_expr); |
370 | self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(self.err_ty()) | 370 | self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or_else(|| self.err_ty()) |
371 | } | 371 | } |
372 | Expr::Continue { .. } => TyKind::Never.intern(&Interner), | 372 | Expr::Continue { .. } => TyKind::Never.intern(&Interner), |
373 | Expr::Break { expr, label } => { | 373 | Expr::Break { expr, label } => { |
@@ -511,7 +511,7 @@ impl<'a> InferenceContext<'a> { | |||
511 | _ => None, | 511 | _ => None, |
512 | } | 512 | } |
513 | }) | 513 | }) |
514 | .unwrap_or(self.err_ty()); | 514 | .unwrap_or_else(|| self.err_ty()); |
515 | let ty = self.insert_type_vars(ty); | 515 | let ty = self.insert_type_vars(ty); |
516 | self.normalize_associated_types_in(ty) | 516 | self.normalize_associated_types_in(ty) |
517 | } | 517 | } |
@@ -818,8 +818,10 @@ impl<'a> InferenceContext<'a> { | |||
818 | for stmt in statements { | 818 | for stmt in statements { |
819 | match stmt { | 819 | match stmt { |
820 | Statement::Let { pat, type_ref, initializer } => { | 820 | Statement::Let { pat, type_ref, initializer } => { |
821 | let decl_ty = | 821 | let decl_ty = type_ref |
822 | type_ref.as_ref().map(|tr| self.make_ty(tr)).unwrap_or(self.err_ty()); | 822 | .as_ref() |
823 | .map(|tr| self.make_ty(tr)) | ||
824 | .unwrap_or_else(|| self.err_ty()); | ||
823 | 825 | ||
824 | // Always use the declared type when specified | 826 | // Always use the declared type when specified |
825 | let mut ty = decl_ty.clone(); | 827 | let mut ty = decl_ty.clone(); |