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/diagnostics/expr.rs | 2 +- crates/hir_ty/src/infer/expr.rs | 10 ++++++---- crates/hir_ty/src/infer/pat.rs | 2 +- crates/hir_ty/src/lower.rs | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) (limited to 'crates/hir_ty/src') diff --git a/crates/hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs index b809b96a0..dc8f20138 100644 --- a/crates/hir_ty/src/diagnostics/expr.rs +++ b/crates/hir_ty/src/diagnostics/expr.rs @@ -56,7 +56,7 @@ impl BodyValidationDiagnostic { pub fn collect(db: &dyn HirDatabase, owner: DefWithBodyId) -> Vec { let _p = profile::span("BodyValidationDiagnostic::collect"); let infer = db.infer(owner); - let mut validator = ExprValidator::new(owner, infer.clone()); + let mut validator = ExprValidator::new(owner, infer); validator.validate_body(db); validator.diagnostics } 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 { diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 817a65c20..ea03b6a6c 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -562,7 +562,7 @@ impl<'a> TyLoweringContext<'a> { }, ); - ty.unwrap_or(TyKind::Error.intern(&Interner)) + ty.unwrap_or_else(|| TyKind::Error.intern(&Interner)) } else { TyKind::Error.intern(&Interner) } -- cgit v1.2.3