From 8206939fed0e2307455d46620ee114f74ab35d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Wed, 26 May 2021 18:34:50 +0300 Subject: clippy::redundant_clone fixes --- crates/hir_ty/src/infer/coerce.rs | 12 ++++++------ crates/hir_ty/src/infer/expr.rs | 11 +++++------ crates/hir_ty/src/infer/pat.rs | 9 ++++----- 3 files changed, 15 insertions(+), 17 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index 765a02b1c..03b97e7db 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs @@ -76,17 +76,17 @@ impl<'a> InferenceContext<'a> { // way around first would mean we make the type variable `!`, instead of // just marking it as possibly diverging. if self.coerce(&ty2, &ty1) { - ty1.clone() + ty1 } else if self.coerce(&ty1, &ty2) { - ty2.clone() + ty2 } else { if let Some(id) = id { self.result .type_mismatches - .insert(id.into(), TypeMismatch { expected: ty1.clone(), actual: ty2.clone() }); + .insert(id.into(), TypeMismatch { expected: ty1.clone(), actual: ty2 }); } cov_mark::hit!(coerce_merge_fail_fallback); - ty1.clone() + ty1 } } @@ -183,7 +183,7 @@ impl<'a> InferenceContext<'a> { // details of coercion errors though, so I think it's useful to leave // the structure like it is. - let canonicalized = self.canonicalize(from_ty.clone()); + let canonicalized = self.canonicalize(from_ty); let autoderef = autoderef::autoderef( self.db, self.resolver.krate(), @@ -389,7 +389,7 @@ impl<'a> InferenceContext<'a> { // The CoerceUnsized trait should have two generic params: Self and T. return Err(TypeError); } - b.push(coerce_from.clone()).push(to_ty.clone()).build() + b.push(coerce_from).push(to_ty.clone()).build() }; let goal: InEnvironment = diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index eab8fac91..c0cbe19c1 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -44,7 +44,7 @@ impl<'a> InferenceContext<'a> { if !could_unify { self.result.type_mismatches.insert( tgt_expr.into(), - TypeMismatch { expected: expected_ty.clone(), actual: ty.clone() }, + TypeMismatch { expected: expected_ty, actual: ty.clone() }, ); } } @@ -57,15 +57,14 @@ impl<'a> InferenceContext<'a> { let ty = self.infer_expr_inner(expr, &expected); let ty = if let Some(target) = expected.only_has_type(&mut self.table) { if !self.coerce(&ty, &target) { - self.result.type_mismatches.insert( - expr.into(), - TypeMismatch { expected: target.clone(), actual: ty.clone() }, - ); + self.result + .type_mismatches + .insert(expr.into(), TypeMismatch { expected: target, actual: ty.clone() }); // Return actual type when type mismatch. // This is needed for diagnostic when return type mismatch. ty } else { - target.clone() + target } } else { ty diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index 9c8e3b6ae..83e0a7a9e 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs @@ -196,7 +196,7 @@ impl<'a> InferenceContext<'a> { let inner_ty = if let Some(subpat) = subpat { self.infer_pat(*subpat, &expected, default_bm) } else { - expected.clone() + expected }; let inner_ty = self.insert_type_vars_shallow(inner_ty); @@ -266,10 +266,9 @@ impl<'a> InferenceContext<'a> { // use a new type variable if we got error type here let ty = self.insert_type_vars_shallow(ty); if !self.unify(&ty, &expected) { - self.result.type_mismatches.insert( - pat.into(), - TypeMismatch { expected: expected.clone(), actual: ty.clone() }, - ); + self.result + .type_mismatches + .insert(pat.into(), TypeMismatch { expected: expected, actual: ty.clone() }); } self.write_pat_ty(pat, ty.clone()); ty -- cgit v1.2.3