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/code_model.rs | 5 ++-- crates/ra_hir/src/traits.rs | 9 +++----- 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 +++----- 5 files changed, 38 insertions(+), 56 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 9c02b3995..6ee6bd627 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -281,9 +281,8 @@ impl Module { for impl_block in self.impl_blocks(db) { for item in impl_block.items(db) { - match item { - crate::ImplItem::Method(f) => f.diagnostics(db, sink), - _ => (), + if let crate::ImplItem::Method(f) = item { + f.diagnostics(db, sink); } } } diff --git a/crates/ra_hir/src/traits.rs b/crates/ra_hir/src/traits.rs index 2a7c2b791..967654e97 100644 --- a/crates/ra_hir/src/traits.rs +++ b/crates/ra_hir/src/traits.rs @@ -77,13 +77,10 @@ impl TraitItemsIndex { pub(crate) fn trait_items_index(db: &impl DefDatabase, module: Module) -> TraitItemsIndex { let mut index = TraitItemsIndex { traits_by_def: FxHashMap::default() }; for decl in module.declarations(db) { - match decl { - crate::ModuleDef::Trait(tr) => { - for item in tr.trait_data(db).items() { - index.traits_by_def.insert(*item, tr); - } + if let crate::ModuleDef::Trait(tr) = decl { + for item in tr.trait_data(db).items() { + index.traits_by_def.insert(*item, tr); } - _ => {} } } index 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