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) {
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);
}
}
}

View file

@ -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);
}
}
}

View file

@ -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

View file

@ -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(_) => {}
}
_ => {}
},
_ => {}
}
}
}

View file

@ -192,23 +192,20 @@ fn iterate_trait_method_candidates<T>(
// 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<T>(
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);
}
}
_ => {}
}
}
}

View file

@ -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));
}

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) {
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)
}
}
_ => {}
},
_ => {}
}
};
}
}

View file

@ -141,15 +141,14 @@ impl Server {
R::Params: Serialize,
{
let actual = self.send_request::<R>(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 => {}
);
}
}

View file

@ -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)
}
_ => (),
}
}
}