Fix clippy::single_match

This commit is contained in:
Alan Du 2019-06-03 10:01:10 -04:00
parent 354db651da
commit ecd420636e
9 changed files with 51 additions and 76 deletions

View file

@ -31,18 +31,16 @@ pub fn run(verbose: bool, path: &str, only: Option<&str>) -> Result<()> {
for decl in module.declarations(&db) { for decl in module.declarations(&db) {
num_decls += 1; num_decls += 1;
match decl { if let ModuleDef::Function(f) = decl {
ModuleDef::Function(f) => funcs.push(f), funcs.push(f);
_ => {}
} }
} }
for impl_block in module.impl_blocks(&db) { for impl_block in module.impl_blocks(&db) {
for item in impl_block.items(&db) { for item in impl_block.items(&db) {
num_decls += 1; num_decls += 1;
match item { if let ImplItem::Method(f) = item {
ImplItem::Method(f) => funcs.push(f), funcs.push(f);
_ => {}
} }
} }
} }

View file

@ -281,9 +281,8 @@ impl Module {
for impl_block in self.impl_blocks(db) { for impl_block in self.impl_blocks(db) {
for item in impl_block.items(db) { for item in impl_block.items(db) {
match item { if let crate::ImplItem::Method(f) = item {
crate::ImplItem::Method(f) => f.diagnostics(db, sink), f.diagnostics(db, sink);
_ => (),
} }
} }
} }

View file

@ -77,13 +77,10 @@ impl TraitItemsIndex {
pub(crate) fn trait_items_index(db: &impl DefDatabase, module: Module) -> TraitItemsIndex { pub(crate) fn trait_items_index(db: &impl DefDatabase, module: Module) -> TraitItemsIndex {
let mut index = TraitItemsIndex { traits_by_def: FxHashMap::default() }; let mut index = TraitItemsIndex { traits_by_def: FxHashMap::default() };
for decl in module.declarations(db) { for decl in module.declarations(db) {
match decl { if let crate::ModuleDef::Trait(tr) = decl {
crate::ModuleDef::Trait(tr) => { for item in tr.trait_data(db).items() {
for item in tr.trait_data(db).items() { index.traits_by_def.insert(*item, tr);
index.traits_by_def.insert(*item, tr);
}
} }
_ => {}
} }
} }
index index

View file

@ -848,28 +848,23 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
} }
fn register_obligations_for_call(&mut self, callable_ty: &Ty) { fn register_obligations_for_call(&mut self, callable_ty: &Ty) {
match callable_ty { if let Ty::Apply(a_ty) = callable_ty {
Ty::Apply(a_ty) => match a_ty.ctor { if let TypeCtor::FnDef(def) = a_ty.ctor {
TypeCtor::FnDef(def) => { // add obligation for trait implementation, if this is a trait method
// 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
// FIXME also register obligations from where clauses from the trait or impl and method match def {
match def { CallableDef::Function(f) => {
CallableDef::Function(f) => { if let Some(trait_) = f.parent_trait(self.db) {
if let Some(trait_) = f.parent_trait(self.db) { // construct a TraitDef
// construct a TraitDef let substs = a_ty.parameters.prefix(
let substs = a_ty.parameters.prefix( trait_.generic_params(self.db).count_params_including_parent(),
trait_.generic_params(self.db).count_params_including_parent(), );
); self.obligations.push(Obligation::Trait(TraitRef { trait_, substs }));
self.obligations
.push(Obligation::Trait(TraitRef { trait_, substs }));
}
} }
CallableDef::Struct(_) | CallableDef::EnumVariant(_) => {}
} }
CallableDef::Struct(_) | CallableDef::EnumVariant(_) => {}
} }
_ => {} }
},
_ => {}
} }
} }

View file

@ -192,23 +192,20 @@ fn iterate_trait_method_candidates<T>(
// iteration // iteration
let mut known_implemented = false; let mut known_implemented = false;
for item in data.items() { for item in data.items() {
match item { if let TraitItem::Function(m) = *item {
&TraitItem::Function(m) => { let sig = m.signature(db);
let sig = m.signature(db); if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() {
if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() { if !known_implemented {
if !known_implemented { let trait_ref = canonical_trait_ref(db, t, ty.clone());
let trait_ref = canonical_trait_ref(db, t, ty.clone()); if db.implements(krate, trait_ref).is_none() {
if db.implements(krate, trait_ref).is_none() { continue 'traits;
continue 'traits;
}
}
known_implemented = true;
if let Some(result) = callback(&ty.value, m) {
return Some(result);
} }
} }
known_implemented = true;
if let Some(result) = callback(&ty.value, m) {
return Some(result);
}
} }
_ => {}
} }
} }
} }
@ -230,16 +227,13 @@ fn iterate_inherent_methods<T>(
for impl_block in impls.lookup_impl_blocks(&ty.value) { for impl_block in impls.lookup_impl_blocks(&ty.value) {
for item in impl_block.items(db) { for item in impl_block.items(db) {
match item { if let ImplItem::Method(f) = item {
ImplItem::Method(f) => { let sig = f.signature(db);
let sig = f.signature(db); if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() {
if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() { if let Some(result) = callback(&ty.value, f) {
if let Some(result) = callback(&ty.value, f) { return Some(result);
return Some(result);
}
} }
} }
_ => {}
} }
} }
} }

View file

@ -211,13 +211,10 @@ fn convert_where_clauses(
// anyway), otherwise Chalk can easily get into slow situations // anyway), otherwise Chalk can easily get into slow situations
return vec![pred.clone().subst(substs).to_chalk(db)]; return vec![pred.clone().subst(substs).to_chalk(db)];
} }
match pred { if let GenericPredicate::Implemented(trait_ref) = pred {
GenericPredicate::Implemented(trait_ref) => { if blacklisted_trait(db, trait_ref.trait_) {
if blacklisted_trait(db, trait_ref.trait_) { continue;
continue;
}
} }
_ => {}
} }
result.push(pred.clone().subst(substs).to_chalk(db)); result.push(pred.clone().subst(substs).to_chalk(db));
} }

View file

@ -16,8 +16,8 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) {
for receiver in receiver.autoderef(ctx.db) { for receiver in receiver.autoderef(ctx.db) {
match receiver { if let Ty::Apply(a_ty) = receiver {
Ty::Apply(a_ty) => match a_ty.ctor { match a_ty.ctor {
TypeCtor::Adt(AdtDef::Struct(s)) => { TypeCtor::Adt(AdtDef::Struct(s)) => {
for field in s.fields(ctx.db) { for field in s.fields(ctx.db) {
acc.add_field(ctx, field, &a_ty.parameters); acc.add_field(ctx, field, &a_ty.parameters);
@ -30,8 +30,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
} }
} }
_ => {} _ => {}
}, }
_ => {}
}; };
} }
} }

View file

@ -141,15 +141,14 @@ impl Server {
R::Params: Serialize, R::Params: Serialize,
{ {
let actual = self.send_request::<R>(params); let actual = self.send_request::<R>(params);
match find_mismatch(&expected_resp, &actual) { if let Some((expected_part, actual_part)) = find_mismatch(&expected_resp, &actual) {
Some((expected_part, actual_part)) => panic!( panic!(
"JSON mismatch\nExpected:\n{}\nWas:\n{}\nExpected part:\n{}\nActual part:\n{}\n", "JSON mismatch\nExpected:\n{}\nWas:\n{}\nExpected part:\n{}\nActual part:\n{}\n",
to_string_pretty(&expected_resp).unwrap(), to_string_pretty(&expected_resp).unwrap(),
to_string_pretty(&actual).unwrap(), to_string_pretty(&actual).unwrap(),
to_string_pretty(expected_part).unwrap(), to_string_pretty(expected_part).unwrap(),
to_string_pretty(actual_part).unwrap(), to_string_pretty(actual_part).unwrap(),
), );
None => {}
} }
} }

View file

@ -19,13 +19,10 @@ impl Drop for ScopedThread {
log::info!(".. {} terminated with {}", name, if res.is_ok() { "ok" } else { "err" }); log::info!(".. {} terminated with {}", name, if res.is_ok() { "ok" } else { "err" });
// escalate panic, but avoid aborting the process // escalate panic, but avoid aborting the process
match res { if let Err(e) = res {
Err(e) => { if !thread::panicking() {
if !thread::panicking() { panic!(e)
panic!(e)
}
} }
_ => (),
} }
} }
} }