From e3ce88f6f25901b1d33fbc5f931a9d8f90b9e2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Fri, 18 Jun 2021 14:40:51 +0300 Subject: Minor clippy perf fixes --- crates/hir_ty/src/infer/expr.rs | 10 ++++++---- crates/hir_ty/src/infer/pat.rs | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'crates/hir_ty/src/infer') 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> { Expr::Path(p) => { // FIXME this could be more efficient... let resolver = resolver_for_expr(self.db.upcast(), self.owner, tgt_expr); - self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(self.err_ty()) + self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or_else(|| self.err_ty()) } Expr::Continue { .. } => TyKind::Never.intern(&Interner), Expr::Break { expr, label } => { @@ -511,7 +511,7 @@ impl<'a> InferenceContext<'a> { _ => None, } }) - .unwrap_or(self.err_ty()); + .unwrap_or_else(|| self.err_ty()); let ty = self.insert_type_vars(ty); self.normalize_associated_types_in(ty) } @@ -818,8 +818,10 @@ impl<'a> InferenceContext<'a> { for stmt in statements { match stmt { Statement::Let { pat, type_ref, initializer } => { - let decl_ty = - type_ref.as_ref().map(|tr| self.make_ty(tr)).unwrap_or(self.err_ty()); + let decl_ty = type_ref + .as_ref() + .map(|tr| self.make_ty(tr)) + .unwrap_or_else(|| self.err_ty()); // Always use the declared type when specified let mut ty = decl_ty.clone(); diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index 58cb23e9d..c79ed91ea 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs @@ -192,7 +192,7 @@ impl<'a> InferenceContext<'a> { Pat::Path(path) => { // FIXME use correct resolver for the surrounding expression let resolver = self.resolver.clone(); - self.infer_path(&resolver, path, pat.into()).unwrap_or(self.err_ty()) + self.infer_path(&resolver, path, pat.into()).unwrap_or_else(|| self.err_ty()) } Pat::Bind { mode, name: _, subpat } => { let mode = if mode == &BindingAnnotation::Unannotated { -- cgit v1.2.3