aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAlan Du <[email protected]>2019-06-03 15:01:10 +0100
committerAlan Du <[email protected]>2019-06-04 23:05:07 +0100
commitecd420636efe54657ae742ce960ce061740ef108 (patch)
tree612606f7a9f093375a946a69078041f095eb0d8b /crates
parent354db651dafd24d93cf0f151d63ad5ecb2e716e2 (diff)
Fix clippy::single_match
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_cli/src/analysis_stats.rs10
-rw-r--r--crates/ra_hir/src/code_model.rs5
-rw-r--r--crates/ra_hir/src/traits.rs9
-rw-r--r--crates/ra_hir/src/ty/infer.rs33
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs38
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs9
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs7
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs7
-rw-r--r--crates/thread_worker/src/lib.rs9
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<()> {
31 31
32 for decl in module.declarations(&db) { 32 for decl in module.declarations(&db) {
33 num_decls += 1; 33 num_decls += 1;
34 match decl { 34 if let ModuleDef::Function(f) = decl {
35 ModuleDef::Function(f) => funcs.push(f), 35 funcs.push(f);
36 _ => {}
37 } 36 }
38 } 37 }
39 38
40 for impl_block in module.impl_blocks(&db) { 39 for impl_block in module.impl_blocks(&db) {
41 for item in impl_block.items(&db) { 40 for item in impl_block.items(&db) {
42 num_decls += 1; 41 num_decls += 1;
43 match item { 42 if let ImplItem::Method(f) = item {
44 ImplItem::Method(f) => funcs.push(f), 43 funcs.push(f);
45 _ => {}
46 } 44 }
47 } 45 }
48 } 46 }
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 {
281 281
282 for impl_block in self.impl_blocks(db) { 282 for impl_block in self.impl_blocks(db) {
283 for item in impl_block.items(db) { 283 for item in impl_block.items(db) {
284 match item { 284 if let crate::ImplItem::Method(f) = item {
285 crate::ImplItem::Method(f) => f.diagnostics(db, sink), 285 f.diagnostics(db, sink);
286 _ => (),
287 } 286 }
288 } 287 }
289 } 288 }
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 {
77 pub(crate) fn trait_items_index(db: &impl DefDatabase, module: Module) -> TraitItemsIndex { 77 pub(crate) fn trait_items_index(db: &impl DefDatabase, module: Module) -> TraitItemsIndex {
78 let mut index = TraitItemsIndex { traits_by_def: FxHashMap::default() }; 78 let mut index = TraitItemsIndex { traits_by_def: FxHashMap::default() };
79 for decl in module.declarations(db) { 79 for decl in module.declarations(db) {
80 match decl { 80 if let crate::ModuleDef::Trait(tr) = decl {
81 crate::ModuleDef::Trait(tr) => { 81 for item in tr.trait_data(db).items() {
82 for item in tr.trait_data(db).items() { 82 index.traits_by_def.insert(*item, tr);
83 index.traits_by_def.insert(*item, tr);
84 }
85 } 83 }
86 _ => {}
87 } 84 }
88 } 85 }
89 index 86 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> {
848 } 848 }
849 849
850 fn register_obligations_for_call(&mut self, callable_ty: &Ty) { 850 fn register_obligations_for_call(&mut self, callable_ty: &Ty) {
851 match callable_ty { 851 if let Ty::Apply(a_ty) = callable_ty {
852 Ty::Apply(a_ty) => match a_ty.ctor { 852 if let TypeCtor::FnDef(def) = a_ty.ctor {
853 TypeCtor::FnDef(def) => { 853 // add obligation for trait implementation, if this is a trait method
854 // add obligation for trait implementation, if this is a trait method 854 // FIXME also register obligations from where clauses from the trait or impl and method
855 // FIXME also register obligations from where clauses from the trait or impl and method 855 match def {
856 match def { 856 CallableDef::Function(f) => {
857 CallableDef::Function(f) => { 857 if let Some(trait_) = f.parent_trait(self.db) {
858 if let Some(trait_) = f.parent_trait(self.db) { 858 // construct a TraitDef
859 // construct a TraitDef 859 let substs = a_ty.parameters.prefix(
860 let substs = a_ty.parameters.prefix( 860 trait_.generic_params(self.db).count_params_including_parent(),
861 trait_.generic_params(self.db).count_params_including_parent(), 861 );
862 ); 862 self.obligations.push(Obligation::Trait(TraitRef { trait_, substs }));
863 self.obligations
864 .push(Obligation::Trait(TraitRef { trait_, substs }));
865 }
866 } 863 }
867 CallableDef::Struct(_) | CallableDef::EnumVariant(_) => {}
868 } 864 }
865 CallableDef::Struct(_) | CallableDef::EnumVariant(_) => {}
869 } 866 }
870 _ => {} 867 }
871 },
872 _ => {}
873 } 868 }
874 } 869 }
875 870
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<T>(
192 // iteration 192 // iteration
193 let mut known_implemented = false; 193 let mut known_implemented = false;
194 for item in data.items() { 194 for item in data.items() {
195 match item { 195 if let TraitItem::Function(m) = *item {
196 &TraitItem::Function(m) => { 196 let sig = m.signature(db);
197 let sig = m.signature(db); 197 if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() {
198 if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() { 198 if !known_implemented {
199 if !known_implemented { 199 let trait_ref = canonical_trait_ref(db, t, ty.clone());
200 let trait_ref = canonical_trait_ref(db, t, ty.clone()); 200 if db.implements(krate, trait_ref).is_none() {
201 if db.implements(krate, trait_ref).is_none() { 201 continue 'traits;
202 continue 'traits;
203 }
204 }
205 known_implemented = true;
206 if let Some(result) = callback(&ty.value, m) {
207 return Some(result);
208 } 202 }
209 } 203 }
204 known_implemented = true;
205 if let Some(result) = callback(&ty.value, m) {
206 return Some(result);
207 }
210 } 208 }
211 _ => {}
212 } 209 }
213 } 210 }
214 } 211 }
@@ -230,16 +227,13 @@ fn iterate_inherent_methods<T>(
230 227
231 for impl_block in impls.lookup_impl_blocks(&ty.value) { 228 for impl_block in impls.lookup_impl_blocks(&ty.value) {
232 for item in impl_block.items(db) { 229 for item in impl_block.items(db) {
233 match item { 230 if let ImplItem::Method(f) = item {
234 ImplItem::Method(f) => { 231 let sig = f.signature(db);
235 let sig = f.signature(db); 232 if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() {
236 if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() { 233 if let Some(result) = callback(&ty.value, f) {
237 if let Some(result) = callback(&ty.value, f) { 234 return Some(result);
238 return Some(result);
239 }
240 } 235 }
241 } 236 }
242 _ => {}
243 } 237 }
244 } 238 }
245 } 239 }
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(
211 // anyway), otherwise Chalk can easily get into slow situations 211 // anyway), otherwise Chalk can easily get into slow situations
212 return vec![pred.clone().subst(substs).to_chalk(db)]; 212 return vec![pred.clone().subst(substs).to_chalk(db)];
213 } 213 }
214 match pred { 214 if let GenericPredicate::Implemented(trait_ref) = pred {
215 GenericPredicate::Implemented(trait_ref) => { 215 if blacklisted_trait(db, trait_ref.trait_) {
216 if blacklisted_trait(db, trait_ref.trait_) { 216 continue;
217 continue;
218 }
219 } 217 }
220 _ => {}
221 } 218 }
222 result.push(pred.clone().subst(substs).to_chalk(db)); 219 result.push(pred.clone().subst(substs).to_chalk(db));
223 } 220 }
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) {
16 16
17fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { 17fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) {
18 for receiver in receiver.autoderef(ctx.db) { 18 for receiver in receiver.autoderef(ctx.db) {
19 match receiver { 19 if let Ty::Apply(a_ty) = receiver {
20 Ty::Apply(a_ty) => match a_ty.ctor { 20 match a_ty.ctor {
21 TypeCtor::Adt(AdtDef::Struct(s)) => { 21 TypeCtor::Adt(AdtDef::Struct(s)) => {
22 for field in s.fields(ctx.db) { 22 for field in s.fields(ctx.db) {
23 acc.add_field(ctx, field, &a_ty.parameters); 23 acc.add_field(ctx, field, &a_ty.parameters);
@@ -30,8 +30,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
30 } 30 }
31 } 31 }
32 _ => {} 32 _ => {}
33 }, 33 }
34 _ => {}
35 }; 34 };
36 } 35 }
37} 36}
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 {
141 R::Params: Serialize, 141 R::Params: Serialize,
142 { 142 {
143 let actual = self.send_request::<R>(params); 143 let actual = self.send_request::<R>(params);
144 match find_mismatch(&expected_resp, &actual) { 144 if let Some((expected_part, actual_part)) = find_mismatch(&expected_resp, &actual) {
145 Some((expected_part, actual_part)) => panic!( 145 panic!(
146 "JSON mismatch\nExpected:\n{}\nWas:\n{}\nExpected part:\n{}\nActual part:\n{}\n", 146 "JSON mismatch\nExpected:\n{}\nWas:\n{}\nExpected part:\n{}\nActual part:\n{}\n",
147 to_string_pretty(&expected_resp).unwrap(), 147 to_string_pretty(&expected_resp).unwrap(),
148 to_string_pretty(&actual).unwrap(), 148 to_string_pretty(&actual).unwrap(),
149 to_string_pretty(expected_part).unwrap(), 149 to_string_pretty(expected_part).unwrap(),
150 to_string_pretty(actual_part).unwrap(), 150 to_string_pretty(actual_part).unwrap(),
151 ), 151 );
152 None => {}
153 } 152 }
154 } 153 }
155 154
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 {
19 log::info!(".. {} terminated with {}", name, if res.is_ok() { "ok" } else { "err" }); 19 log::info!(".. {} terminated with {}", name, if res.is_ok() { "ok" } else { "err" });
20 20
21 // escalate panic, but avoid aborting the process 21 // escalate panic, but avoid aborting the process
22 match res { 22 if let Err(e) = res {
23 Err(e) => { 23 if !thread::panicking() {
24 if !thread::panicking() { 24 panic!(e)
25 panic!(e)
26 }
27 } 25 }
28 _ => (),
29 } 26 }
30 } 27 }
31} 28}