From ecd420636efe54657ae742ce960ce061740ef108 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Mon, 3 Jun 2019 10:01:10 -0400 Subject: Fix clippy::single_match --- crates/ra_hir/src/ty/infer.rs | 33 ++++++++++++--------------- crates/ra_hir/src/ty/method_resolution.rs | 38 +++++++++++++------------------ crates/ra_hir/src/ty/traits/chalk.rs | 9 +++----- 3 files changed, 33 insertions(+), 47 deletions(-) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index e8ae33ead..1723921e6 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -848,28 +848,23 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } fn register_obligations_for_call(&mut self, callable_ty: &Ty) { - match callable_ty { - Ty::Apply(a_ty) => match a_ty.ctor { - TypeCtor::FnDef(def) => { - // add obligation for trait implementation, if this is a trait method - // FIXME also register obligations from where clauses from the trait or impl and method - match def { - CallableDef::Function(f) => { - if let Some(trait_) = f.parent_trait(self.db) { - // construct a TraitDef - let substs = a_ty.parameters.prefix( - trait_.generic_params(self.db).count_params_including_parent(), - ); - self.obligations - .push(Obligation::Trait(TraitRef { trait_, substs })); - } + if let Ty::Apply(a_ty) = callable_ty { + if let TypeCtor::FnDef(def) = a_ty.ctor { + // add obligation for trait implementation, if this is a trait method + // FIXME also register obligations from where clauses from the trait or impl and method + match def { + CallableDef::Function(f) => { + if let Some(trait_) = f.parent_trait(self.db) { + // construct a TraitDef + let substs = a_ty.parameters.prefix( + trait_.generic_params(self.db).count_params_including_parent(), + ); + self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); } - CallableDef::Struct(_) | CallableDef::EnumVariant(_) => {} } + CallableDef::Struct(_) | CallableDef::EnumVariant(_) => {} } - _ => {} - }, - _ => {} + } } } diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index 34817a5ec..646e58aa9 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -192,23 +192,20 @@ fn iterate_trait_method_candidates( // iteration let mut known_implemented = false; for item in data.items() { - match item { - &TraitItem::Function(m) => { - let sig = m.signature(db); - if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() { - if !known_implemented { - let trait_ref = canonical_trait_ref(db, t, ty.clone()); - if db.implements(krate, trait_ref).is_none() { - continue 'traits; - } - } - known_implemented = true; - if let Some(result) = callback(&ty.value, m) { - return Some(result); + if let TraitItem::Function(m) = *item { + let sig = m.signature(db); + if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() { + if !known_implemented { + let trait_ref = canonical_trait_ref(db, t, ty.clone()); + if db.implements(krate, trait_ref).is_none() { + continue 'traits; } } + known_implemented = true; + if let Some(result) = callback(&ty.value, m) { + return Some(result); + } } - _ => {} } } } @@ -230,16 +227,13 @@ fn iterate_inherent_methods( for impl_block in impls.lookup_impl_blocks(&ty.value) { for item in impl_block.items(db) { - match item { - ImplItem::Method(f) => { - let sig = f.signature(db); - if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() { - if let Some(result) = callback(&ty.value, f) { - return Some(result); - } + if let ImplItem::Method(f) = item { + let sig = f.signature(db); + if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() { + if let Some(result) = callback(&ty.value, f) { + return Some(result); } } - _ => {} } } } diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 78440b258..1e4806db0 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs @@ -211,13 +211,10 @@ fn convert_where_clauses( // anyway), otherwise Chalk can easily get into slow situations return vec![pred.clone().subst(substs).to_chalk(db)]; } - match pred { - GenericPredicate::Implemented(trait_ref) => { - if blacklisted_trait(db, trait_ref.trait_) { - continue; - } + if let GenericPredicate::Implemented(trait_ref) = pred { + if blacklisted_trait(db, trait_ref.trait_) { + continue; } - _ => {} } result.push(pred.clone().subst(substs).to_chalk(db)); } -- cgit v1.2.3 From fb592d76aa24e8fe74694038c283f56ea83ab568 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 4 Jun 2019 02:28:50 -0400 Subject: Fix clippy::into_iter_on_ref --- crates/ra_hir/src/ty/infer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 1723921e6..58cfcd8a2 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -1044,7 +1044,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { Expr::StructLit { path, fields, spread } => { let (ty, def_id) = self.resolve_variant(path.as_ref()); let substs = ty.substs().unwrap_or_else(Substs::empty); - for (field_idx, field) in fields.into_iter().enumerate() { + for (field_idx, field) in fields.iter().enumerate() { let field_ty = def_id .and_then(|it| match it.field(self.db, &field.name) { Some(field) => Some(field), -- cgit v1.2.3 From 40424d4222d4630bc53294d10f1718f2d3d300de Mon Sep 17 00:00:00 2001 From: Alan Du Date: Mon, 3 Jun 2019 10:21:08 -0400 Subject: Fix clippy::identity_conversion --- crates/ra_hir/src/ty/infer.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 58cfcd8a2..5edc59f18 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -539,7 +539,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } })?; - resolved = Resolution::Def(item.into()); + resolved = Resolution::Def(item); } match resolved { @@ -762,7 +762,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { _ => &Ty::Unknown, }; let subty = self.infer_pat(*pat, expectation, default_bm); - Ty::apply_one(TypeCtor::Ref(*mutability), subty.into()) + Ty::apply_one(TypeCtor::Ref(*mutability), subty) } Pat::TupleStruct { path: ref p, args: ref subpats } => { self.infer_tuple_struct_pat(p.as_ref(), subpats, expected, default_bm) @@ -790,7 +790,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let bound_ty = match mode { BindingMode::Ref(mutability) => { - Ty::apply_one(TypeCtor::Ref(mutability), inner_ty.clone().into()) + Ty::apply_one(TypeCtor::Ref(mutability), inner_ty.clone()) } BindingMode::Move => inner_ty.clone(), }; -- cgit v1.2.3 From b28ca32db22d5e2ed34db556c6fd50a5fc2d679c Mon Sep 17 00:00:00 2001 From: Alan Du Date: Mon, 3 Jun 2019 10:27:51 -0400 Subject: Fix clippy::or_fun_call --- crates/ra_hir/src/ty/infer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 5edc59f18..905fe9f0e 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -462,7 +462,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let mut resolved = if remaining_index.is_none() { def.take_values()? } else { def.take_types()? }; - let remaining_index = remaining_index.unwrap_or(path.segments.len()); + let remaining_index = remaining_index.unwrap_or_else(|| path.segments.len()); let mut actual_def_ty: Option = None; let krate = resolver.krate()?; -- cgit v1.2.3