From c9b4ac5be4daaabc062ab1ee663eba8594750003 Mon Sep 17 00:00:00 2001 From: Maan2003 Date: Sun, 13 Jun 2021 09:24:16 +0530 Subject: clippy::redudant_borrow --- .../hir_ty/src/diagnostics/match_check/deconstruct_pat.rs | 2 +- crates/hir_ty/src/diagnostics/match_check/usefulness.rs | 6 +++--- crates/hir_ty/src/infer.rs | 2 +- crates/hir_ty/src/infer/coerce.rs | 2 +- crates/hir_ty/src/infer/expr.rs | 12 ++++++------ crates/hir_ty/src/infer/pat.rs | 2 +- crates/hir_ty/src/infer/path.rs | 6 +++--- crates/hir_ty/src/interner.rs | 6 +++--- crates/hir_ty/src/lower.rs | 6 +++--- crates/hir_ty/src/method_resolution.rs | 14 +++++++------- 10 files changed, 29 insertions(+), 29 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/diagnostics/match_check/deconstruct_pat.rs b/crates/hir_ty/src/diagnostics/match_check/deconstruct_pat.rs index 222141bd6..088d2791e 100644 --- a/crates/hir_ty/src/diagnostics/match_check/deconstruct_pat.rs +++ b/crates/hir_ty/src/diagnostics/match_check/deconstruct_pat.rs @@ -528,7 +528,7 @@ impl SplitWildcard { smallvec![NonExhaustive] } TyKind::Never => SmallVec::new(), - _ if cx.is_uninhabited(&pcx.ty) => SmallVec::new(), + _ if cx.is_uninhabited(pcx.ty) => SmallVec::new(), TyKind::Adt(..) | TyKind::Tuple(..) | TyKind::Ref(..) => smallvec![Single], // This type is one for which we cannot list constructors, like `str` or `f64`. _ => smallvec![NonExhaustive], diff --git a/crates/hir_ty/src/diagnostics/match_check/usefulness.rs b/crates/hir_ty/src/diagnostics/match_check/usefulness.rs index bd76a606c..f5ac71444 100644 --- a/crates/hir_ty/src/diagnostics/match_check/usefulness.rs +++ b/crates/hir_ty/src/diagnostics/match_check/usefulness.rs @@ -645,7 +645,7 @@ impl SubPatSet { (Seq { subpats: s_set }, Seq { subpats: mut o_set }) => { s_set.retain(|i, s_sub_set| { // Missing entries count as full. - let o_sub_set = o_set.remove(&i).unwrap_or(Full); + let o_sub_set = o_set.remove(i).unwrap_or(Full); s_sub_set.union(o_sub_set); // We drop full entries. !s_sub_set.is_full() @@ -656,7 +656,7 @@ impl SubPatSet { (Alt { subpats: s_set, .. }, Alt { subpats: mut o_set, .. }) => { s_set.retain(|i, s_sub_set| { // Missing entries count as empty. - let o_sub_set = o_set.remove(&i).unwrap_or(Empty); + let o_sub_set = o_set.remove(i).unwrap_or(Empty); s_sub_set.union(o_sub_set); // We drop empty entries. !s_sub_set.is_empty() @@ -898,7 +898,7 @@ impl Usefulness { } else { witnesses .into_iter() - .map(|witness| witness.apply_constructor(pcx, &ctor, ctor_wild_subpatterns)) + .map(|witness| witness.apply_constructor(pcx, ctor, ctor_wild_subpatterns)) .collect() }; WithWitnesses(new_witnesses) diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index f023c1fb7..9590c2e47 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs @@ -782,7 +782,7 @@ impl Expectation { fn adjust_for_branches(&self, table: &mut unify::InferenceTable) -> Expectation { match self { Expectation::HasType(ety) => { - let ety = table.resolve_ty_shallow(&ety); + let ety = table.resolve_ty_shallow(ety); if !ety.is_ty_var() { Expectation::HasType(ety) } else { diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index 03b97e7db..8647d7437 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs @@ -109,7 +109,7 @@ impl<'a> InferenceContext<'a> { } // Consider coercing the subtype to a DST - if let Ok(ret) = self.try_coerce_unsized(&from_ty, &to_ty) { + if let Ok(ret) = self.try_coerce_unsized(&from_ty, to_ty) { return Ok(ret); } diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index e34f194ff..4805c0a00 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -54,7 +54,7 @@ impl<'a> InferenceContext<'a> { /// Infer type of expression with possibly implicit coerce to the expected type. /// Return the type after possible coercion. pub(super) fn infer_expr_coerce(&mut self, expr: ExprId, expected: &Expectation) -> Ty { - let ty = self.infer_expr_inner(expr, &expected); + 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 @@ -135,11 +135,11 @@ impl<'a> InferenceContext<'a> { let mut both_arms_diverge = Diverges::Always; let mut result_ty = self.table.new_type_var(); - let then_ty = self.infer_expr_inner(*then_branch, &expected); + let then_ty = self.infer_expr_inner(*then_branch, expected); both_arms_diverge &= mem::replace(&mut self.diverges, Diverges::Maybe); result_ty = self.coerce_merge_branch(Some(*then_branch), &result_ty, &then_ty); let else_ty = match else_branch { - Some(else_branch) => self.infer_expr_inner(*else_branch, &expected), + Some(else_branch) => self.infer_expr_inner(*else_branch, expected), None => TyBuilder::unit(), }; both_arms_diverge &= self.diverges; @@ -330,8 +330,8 @@ impl<'a> InferenceContext<'a> { .infer_method_call( tgt_expr, *receiver, - &args, - &method_name, + args, + method_name, generic_args.as_deref(), ), Expr::Match { expr, arms } => { @@ -993,7 +993,7 @@ impl<'a> InferenceContext<'a> { } fn register_obligations_for_call(&mut self, callable_ty: &Ty) { - let callable_ty = self.resolve_ty_shallow(&callable_ty); + let callable_ty = self.resolve_ty_shallow(callable_ty); if let TyKind::FnDef(fn_def, parameters) = callable_ty.kind(&Interner) { let def: CallableDefId = from_chalk(self.db, *fn_def); let generic_predicates = self.db.generic_predicates(def.into()); diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index 25dff7e49..8f5db1f40 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(self.err_ty()) } Pat::Bind { mode, name: _, subpat } => { let mode = if mode == &BindingAnnotation::Unannotated { diff --git a/crates/hir_ty/src/infer/path.rs b/crates/hir_ty/src/infer/path.rs index 14c99eafd..056cdb5d5 100644 --- a/crates/hir_ty/src/infer/path.rs +++ b/crates/hir_ty/src/infer/path.rs @@ -43,11 +43,11 @@ impl<'a> InferenceContext<'a> { } let ty = self.make_ty(type_ref); let remaining_segments_for_ty = path.segments().take(path.segments().len() - 1); - let ctx = crate::lower::TyLoweringContext::new(self.db, &resolver); + let ctx = crate::lower::TyLoweringContext::new(self.db, resolver); let (ty, _) = ctx.lower_ty_relative_path(ty, None, remaining_segments_for_ty); self.resolve_ty_assoc_item( ty, - &path.segments().last().expect("path had at least one segment").name, + path.segments().last().expect("path had at least one segment").name, id, )? } else { @@ -154,7 +154,7 @@ impl<'a> InferenceContext<'a> { let segment = remaining_segments.last().expect("there should be at least one segment here"); - self.resolve_ty_assoc_item(ty, &segment.name, id) + self.resolve_ty_assoc_item(ty, segment.name, id) } } } diff --git a/crates/hir_ty/src/interner.rs b/crates/hir_ty/src/interner.rs index 29ffdd9b7..5fef878e8 100644 --- a/crates/hir_ty/src/interner.rs +++ b/crates/hir_ty/src/interner.rs @@ -331,7 +331,7 @@ impl chalk_ir::interner::Interner for Interner { &self, clauses: &'a Self::InternedProgramClauses, ) -> &'a [chalk_ir::ProgramClause] { - &clauses + clauses } fn intern_quantified_where_clauses( @@ -373,7 +373,7 @@ impl chalk_ir::interner::Interner for Interner { &self, canonical_var_kinds: &'a Self::InternedCanonicalVarKinds, ) -> &'a [chalk_ir::CanonicalVarKind] { - &canonical_var_kinds + canonical_var_kinds } fn intern_constraints( @@ -413,7 +413,7 @@ impl chalk_ir::interner::Interner for Interner { &self, variances: &'a Self::InternedVariances, ) -> &'a [chalk_ir::Variance] { - &variances + variances } } diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index c83933c73..0b8f21e5d 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -238,7 +238,7 @@ impl<'a> TyLoweringContext<'a> { // away instead of two. let actual_opaque_type_data = self .with_debruijn(DebruijnIndex::INNERMOST, |ctx| { - ctx.lower_impl_trait(&bounds) + ctx.lower_impl_trait(bounds) }); self.opaque_type_data.borrow_mut()[idx as usize] = actual_opaque_type_data; @@ -421,7 +421,7 @@ impl<'a> TyLoweringContext<'a> { let found = self .db .trait_data(trait_ref.hir_trait_id()) - .associated_type_by_name(&segment.name); + .associated_type_by_name(segment.name); match found { Some(associated_ty) => { // FIXME handle type parameters on the segment @@ -505,7 +505,7 @@ impl<'a> TyLoweringContext<'a> { pub(crate) fn lower_path(&self, path: &Path) -> (Ty, Option) { // Resolve the path (in type namespace) if let Some(type_ref) = path.type_anchor() { - let (ty, res) = self.lower_ty_ext(&type_ref); + let (ty, res) = self.lower_ty_ext(type_ref); return self.lower_ty_relative_path(ty, res, path.segments()); } let (resolution, remaining_index) = diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index a23527f7d..8c00a6369 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs @@ -372,7 +372,7 @@ pub(crate) fn lookup_method( db, env, krate, - &traits_in_scope, + traits_in_scope, visible_from_module, Some(name), LookupMode::MethodCall, @@ -484,7 +484,7 @@ fn iterate_method_candidates_impl( LookupMode::Path => { // No autoderef for path lookups iterate_method_candidates_for_self_ty( - &ty, + ty, db, env, krate, @@ -513,7 +513,7 @@ fn iterate_method_candidates_with_autoref( db, env.clone(), krate, - &traits_in_scope, + traits_in_scope, visible_from_module, name, &mut callback, @@ -531,7 +531,7 @@ fn iterate_method_candidates_with_autoref( db, env.clone(), krate, - &traits_in_scope, + traits_in_scope, visible_from_module, name, &mut callback, @@ -549,7 +549,7 @@ fn iterate_method_candidates_with_autoref( db, env, krate, - &traits_in_scope, + traits_in_scope, visible_from_module, name, &mut callback, @@ -593,7 +593,7 @@ fn iterate_method_candidates_by_receiver( db, env.clone(), krate, - &traits_in_scope, + traits_in_scope, name, Some(receiver_ty), &mut callback, @@ -870,7 +870,7 @@ fn transform_receiver_ty( .fill_with_unknown() .build(), AssocContainerId::ImplId(impl_id) => { - let impl_substs = inherent_impl_substs(db, env, impl_id, &self_ty)?; + let impl_substs = inherent_impl_substs(db, env, impl_id, self_ty)?; TyBuilder::subst_for_def(db, function_id) .use_parent_substs(&impl_substs) .fill_with_unknown() -- cgit v1.2.3 From 6cc6dee9e96d55dbbd8593523551a9981a691147 Mon Sep 17 00:00:00 2001 From: Maan2003 Date: Sun, 13 Jun 2021 09:25:55 +0530 Subject: clippy::useless_conversion --- crates/hir_ty/src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/builder.rs b/crates/hir_ty/src/builder.rs index 893e727c2..bb9d84246 100644 --- a/crates/hir_ty/src/builder.rs +++ b/crates/hir_ty/src/builder.rs @@ -202,7 +202,7 @@ impl + Fold> TyBuilder> impl TyBuilder> { pub fn def_ty(db: &dyn HirDatabase, def: TyDefId) -> TyBuilder> { - TyBuilder::subst_binders(db.ty(def.into())) + TyBuilder::subst_binders(db.ty(def)) } pub fn impl_self_ty(db: &dyn HirDatabase, def: hir_def::ImplId) -> TyBuilder> { -- cgit v1.2.3 From 75370312fbfe072947ffdc568eebc9cb4c6108e4 Mon Sep 17 00:00:00 2001 From: Maan2003 Date: Sun, 13 Jun 2021 09:29:36 +0530 Subject: clippy::redundant_closure --- crates/hir_ty/src/chalk_db.rs | 2 +- crates/hir_ty/src/consteval.rs | 2 +- crates/hir_ty/src/lower.rs | 2 +- crates/hir_ty/src/method_resolution.rs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/chalk_db.rs b/crates/hir_ty/src/chalk_db.rs index 4e042bf42..1dab19000 100644 --- a/crates/hir_ty/src/chalk_db.rs +++ b/crates/hir_ty/src/chalk_db.rs @@ -431,7 +431,7 @@ pub(crate) fn trait_datum_query( }; let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars); let associated_ty_ids = - trait_data.associated_types().map(|type_alias| to_assoc_type_id(type_alias)).collect(); + trait_data.associated_types().map(to_assoc_type_id).collect(); let trait_datum_bound = rust_ir::TraitDatumBound { where_clauses }; let well_known = lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name)); diff --git a/crates/hir_ty/src/consteval.rs b/crates/hir_ty/src/consteval.rs index e3ceb3d62..6f0bf8f8c 100644 --- a/crates/hir_ty/src/consteval.rs +++ b/crates/hir_ty/src/consteval.rs @@ -49,7 +49,7 @@ pub fn usize_const(value: Option) -> Const { ConstData { ty: TyKind::Scalar(chalk_ir::Scalar::Uint(chalk_ir::UintTy::Usize)).intern(&Interner), value: ConstValue::Concrete(chalk_ir::ConcreteConst { - interned: value.map(|value| ConstScalar::Usize(value)).unwrap_or(ConstScalar::Unknown), + interned: value.map(ConstScalar::Usize).unwrap_or(ConstScalar::Unknown), }), } .intern(&Interner) diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 0b8f21e5d..a8a9f5ca1 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -784,7 +784,7 @@ impl<'a> TyLoweringContext<'a> { let trait_ref = match bound { TypeBound::Path(path) => { bindings = self.lower_trait_ref_from_path(path, Some(self_ty)); - bindings.clone().map(WhereClause::Implemented).map(|b| crate::wrap_empty_binders(b)) + bindings.clone().map(WhereClause::Implemented).map(crate::wrap_empty_binders) } TypeBound::Lifetime(_) => None, TypeBound::Error => None, diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index 8c00a6369..f3d390961 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs @@ -60,7 +60,7 @@ impl TyFingerprint { TyKind::Adt(AdtId(adt), _) => TyFingerprint::Adt(*adt), TyKind::Raw(mutability, ..) => TyFingerprint::RawPtr(*mutability), TyKind::Foreign(alias_id, ..) => TyFingerprint::ForeignType(*alias_id), - TyKind::Dyn(_) => ty.dyn_trait().map(|trait_| TyFingerprint::Dyn(trait_))?, + TyKind::Dyn(_) => ty.dyn_trait().map(TyFingerprint::Dyn)?, _ => return None, }; Some(fp) @@ -77,7 +77,7 @@ impl TyFingerprint { TyKind::Adt(AdtId(adt), _) => TyFingerprint::Adt(*adt), TyKind::Raw(mutability, ..) => TyFingerprint::RawPtr(*mutability), TyKind::Foreign(alias_id, ..) => TyFingerprint::ForeignType(*alias_id), - TyKind::Dyn(_) => ty.dyn_trait().map(|trait_| TyFingerprint::Dyn(trait_))?, + TyKind::Dyn(_) => ty.dyn_trait().map(TyFingerprint::Dyn)?, TyKind::Ref(_, _, ty) => return TyFingerprint::for_trait_impl(ty), TyKind::Tuple(_, subst) => { let first_ty = subst.interned().get(0).map(|arg| arg.assert_ty_ref(&Interner)); -- cgit v1.2.3 From aabd41cafc1a79f5ad124a31a360ab0442c13efd Mon Sep 17 00:00:00 2001 From: Maan2003 Date: Sun, 13 Jun 2021 09:40:22 +0530 Subject: clippy::redundant_field_names --- crates/hir_ty/src/infer/pat.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index 8f5db1f40..035f4ded6 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs @@ -275,7 +275,7 @@ impl<'a> InferenceContext<'a> { if !self.unify(&ty, &expected) { self.result .type_mismatches - .insert(pat.into(), TypeMismatch { expected: expected, actual: ty.clone() }); + .insert(pat.into(), TypeMismatch { expected, actual: ty.clone() }); } self.write_pat_ty(pat, ty.clone()); ty -- cgit v1.2.3 From 5ac6804bb3a07b959e8c2c3534255a8d6bb4948c Mon Sep 17 00:00:00 2001 From: Maan2003 Date: Sun, 13 Jun 2021 09:48:15 +0530 Subject: cargo fmt --- crates/hir_ty/src/chalk_db.rs | 3 +-- crates/hir_ty/src/infer/expr.rs | 8 +------- 2 files changed, 2 insertions(+), 9 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/chalk_db.rs b/crates/hir_ty/src/chalk_db.rs index 1dab19000..34c3f6bd9 100644 --- a/crates/hir_ty/src/chalk_db.rs +++ b/crates/hir_ty/src/chalk_db.rs @@ -430,8 +430,7 @@ pub(crate) fn trait_datum_query( fundamental: false, }; let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars); - let associated_ty_ids = - trait_data.associated_types().map(to_assoc_type_id).collect(); + let associated_ty_ids = trait_data.associated_types().map(to_assoc_type_id).collect(); let trait_datum_bound = rust_ir::TraitDatumBound { where_clauses }; let well_known = lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name)); diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 4805c0a00..5ea2e5934 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -327,13 +327,7 @@ impl<'a> InferenceContext<'a> { self.normalize_associated_types_in(ret_ty) } Expr::MethodCall { receiver, args, method_name, generic_args } => self - .infer_method_call( - tgt_expr, - *receiver, - args, - method_name, - generic_args.as_deref(), - ), + .infer_method_call(tgt_expr, *receiver, args, method_name, generic_args.as_deref()), Expr::Match { expr, arms } => { let input_ty = self.infer_expr(*expr, &Expectation::none()); -- cgit v1.2.3