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_cli/src/analysis_stats.rs | 10 +++--- 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 ++---- crates/ra_ide_api/src/completion/complete_dot.rs | 7 ++--- crates/ra_lsp_server/tests/heavy_tests/support.rs | 7 ++--- crates/thread_worker/src/lib.rs | 9 ++---- 9 files changed, 51 insertions(+), 76 deletions(-) diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs index b481ace9e..8bb524ce3 100644 --- a/crates/ra_cli/src/analysis_stats.rs +++ b/crates/ra_cli/src/analysis_stats.rs @@ -31,18 +31,16 @@ pub fn run(verbose: bool, path: &str, only: Option<&str>) -> Result<()> { for decl in module.declarations(&db) { num_decls += 1; - match decl { - ModuleDef::Function(f) => funcs.push(f), - _ => {} + if let ModuleDef::Function(f) = decl { + funcs.push(f); } } for impl_block in module.impl_blocks(&db) { for item in impl_block.items(&db) { num_decls += 1; - match item { - ImplItem::Method(f) => funcs.push(f), - _ => {} + if let ImplItem::Method(f) = item { + funcs.push(f); } } } 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)); } diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 5bf289c63..0822a0e7e 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -16,8 +16,8 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { for receiver in receiver.autoderef(ctx.db) { - match receiver { - Ty::Apply(a_ty) => match a_ty.ctor { + if let Ty::Apply(a_ty) = receiver { + match a_ty.ctor { TypeCtor::Adt(AdtDef::Struct(s)) => { for field in s.fields(ctx.db) { acc.add_field(ctx, field, &a_ty.parameters); @@ -30,8 +30,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) } } _ => {} - }, - _ => {} + } }; } } diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs index f952a03a3..955d283dd 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/support.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs @@ -141,15 +141,14 @@ impl Server { R::Params: Serialize, { let actual = self.send_request::(params); - match find_mismatch(&expected_resp, &actual) { - Some((expected_part, actual_part)) => panic!( + if let Some((expected_part, actual_part)) = find_mismatch(&expected_resp, &actual) { + panic!( "JSON mismatch\nExpected:\n{}\nWas:\n{}\nExpected part:\n{}\nActual part:\n{}\n", to_string_pretty(&expected_resp).unwrap(), to_string_pretty(&actual).unwrap(), to_string_pretty(expected_part).unwrap(), to_string_pretty(actual_part).unwrap(), - ), - None => {} + ); } } diff --git a/crates/thread_worker/src/lib.rs b/crates/thread_worker/src/lib.rs index d67e44e38..d8d0d9bf2 100644 --- a/crates/thread_worker/src/lib.rs +++ b/crates/thread_worker/src/lib.rs @@ -19,13 +19,10 @@ impl Drop for ScopedThread { log::info!(".. {} terminated with {}", name, if res.is_ok() { "ok" } else { "err" }); // escalate panic, but avoid aborting the process - match res { - Err(e) => { - if !thread::panicking() { - panic!(e) - } + if let Err(e) = res { + if !thread::panicking() { + panic!(e) } - _ => (), } } } -- cgit v1.2.3