mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Replace if let
with match
where appropriate
This commit is contained in:
parent
f29796da61
commit
9583dd5725
44 changed files with 201 additions and 269 deletions
|
@ -109,10 +109,9 @@ pub(crate) fn deref(
|
|||
ty: InEnvironment<&Canonical<Ty>>,
|
||||
) -> Option<Canonical<Ty>> {
|
||||
let _p = profile::span("deref");
|
||||
if let Some(derefed) = builtin_deref(&ty.goal.value) {
|
||||
Some(Canonical { value: derefed, binders: ty.goal.binders.clone() })
|
||||
} else {
|
||||
deref_by_trait(db, krate, ty)
|
||||
match builtin_deref(&ty.goal.value) {
|
||||
Some(derefed) => Some(Canonical { value: derefed, binders: ty.goal.binders.clone() }),
|
||||
None => deref_by_trait(db, krate, ty),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -104,10 +104,9 @@ impl TyExt for Ty {
|
|||
}
|
||||
|
||||
fn as_fn_def(&self, db: &dyn HirDatabase) -> Option<FunctionId> {
|
||||
if let Some(CallableDefId::FunctionId(func)) = self.callable_def(db) {
|
||||
Some(func)
|
||||
} else {
|
||||
None
|
||||
match self.callable_def(db) {
|
||||
Some(CallableDefId::FunctionId(func)) => Some(func),
|
||||
Some(CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_)) | None => None,
|
||||
}
|
||||
}
|
||||
fn as_reference(&self) -> Option<(&Ty, Lifetime, Mutability)> {
|
||||
|
|
|
@ -105,10 +105,9 @@ impl IntRange {
|
|||
|
||||
#[inline]
|
||||
fn from_range(lo: u128, hi: u128, scalar_ty: Scalar) -> IntRange {
|
||||
if let Scalar::Bool = scalar_ty {
|
||||
IntRange { range: lo..=hi }
|
||||
} else {
|
||||
unimplemented!()
|
||||
match scalar_ty {
|
||||
Scalar::Bool => IntRange { range: lo..=hi },
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -167,10 +167,9 @@ impl<'a> HirFormatter<'a> {
|
|||
}
|
||||
|
||||
pub fn should_truncate(&self) -> bool {
|
||||
if let Some(max_size) = self.max_size {
|
||||
self.curr_size >= max_size
|
||||
} else {
|
||||
false
|
||||
match self.max_size {
|
||||
Some(max_size) => self.curr_size >= max_size,
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -264,10 +264,9 @@ impl<'a> InferenceContext<'a> {
|
|||
|
||||
// collect explicitly written argument types
|
||||
for arg_type in arg_types.iter() {
|
||||
let arg_ty = if let Some(type_ref) = arg_type {
|
||||
self.make_ty(type_ref)
|
||||
} else {
|
||||
self.table.new_type_var()
|
||||
let arg_ty = match arg_type {
|
||||
Some(type_ref) => self.make_ty(type_ref),
|
||||
None => self.table.new_type_var(),
|
||||
};
|
||||
sig_tys.push(arg_ty);
|
||||
}
|
||||
|
|
|
@ -204,10 +204,9 @@ impl<'a> InferenceContext<'a> {
|
|||
} else {
|
||||
BindingMode::convert(*mode)
|
||||
};
|
||||
let inner_ty = if let Some(subpat) = subpat {
|
||||
self.infer_pat(*subpat, &expected, default_bm)
|
||||
} else {
|
||||
expected
|
||||
let inner_ty = match subpat {
|
||||
Some(subpat) => self.infer_pat(*subpat, &expected, default_bm),
|
||||
None => expected,
|
||||
};
|
||||
let inner_ty = self.insert_type_vars_shallow(inner_ty);
|
||||
|
||||
|
|
|
@ -324,10 +324,9 @@ impl<'a> InferenceTable<'a> {
|
|||
|
||||
/// Unify two types and register new trait goals that arise from that.
|
||||
pub(crate) fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool {
|
||||
let result = if let Ok(r) = self.try_unify(ty1, ty2) {
|
||||
r
|
||||
} else {
|
||||
return false;
|
||||
let result = match self.try_unify(ty1, ty2) {
|
||||
Ok(r) => r,
|
||||
Err(_) => return false,
|
||||
};
|
||||
self.register_infer_ok(result);
|
||||
true
|
||||
|
|
|
@ -368,10 +368,9 @@ impl<'a> TyLoweringContext<'a> {
|
|||
Some((it, None)) => it,
|
||||
_ => return None,
|
||||
};
|
||||
if let TypeNs::GenericParam(param_id) = resolution {
|
||||
Some(param_id)
|
||||
} else {
|
||||
None
|
||||
match resolution {
|
||||
TypeNs::GenericParam(param_id) => Some(param_id),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -82,10 +82,9 @@ impl TyFingerprint {
|
|||
TyKind::Ref(_, _, ty) => return TyFingerprint::for_trait_impl(ty),
|
||||
TyKind::Tuple(_, subst) => {
|
||||
let first_ty = subst.interned().get(0).map(|arg| arg.assert_ty_ref(&Interner));
|
||||
if let Some(ty) = first_ty {
|
||||
return TyFingerprint::for_trait_impl(ty);
|
||||
} else {
|
||||
TyFingerprint::Unit
|
||||
match first_ty {
|
||||
Some(ty) => return TyFingerprint::for_trait_impl(ty),
|
||||
None => TyFingerprint::Unit,
|
||||
}
|
||||
}
|
||||
TyKind::AssociatedType(_, _)
|
||||
|
|
|
@ -195,10 +195,9 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
|
|||
mismatch.expected.display_test(&db),
|
||||
mismatch.actual.display_test(&db)
|
||||
);
|
||||
if let Some(annotation) = mismatches.remove(&range) {
|
||||
assert_eq!(actual, annotation);
|
||||
} else {
|
||||
format_to!(unexpected_type_mismatches, "{:?}: {}\n", range.range, actual);
|
||||
match mismatches.remove(&range) {
|
||||
Some(annotation) => assert_eq!(actual, annotation),
|
||||
None => format_to!(unexpected_type_mismatches, "{:?}: {}\n", range.range, actual),
|
||||
}
|
||||
}
|
||||
for (expr, mismatch) in inference_result.expr_type_mismatches() {
|
||||
|
@ -215,10 +214,9 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
|
|||
mismatch.expected.display_test(&db),
|
||||
mismatch.actual.display_test(&db)
|
||||
);
|
||||
if let Some(annotation) = mismatches.remove(&range) {
|
||||
assert_eq!(actual, annotation);
|
||||
} else {
|
||||
format_to!(unexpected_type_mismatches, "{:?}: {}\n", range.range, actual);
|
||||
match mismatches.remove(&range) {
|
||||
Some(annotation) => assert_eq!(actual, annotation),
|
||||
None => format_to!(unexpected_type_mismatches, "{:?}: {}\n", range.range, actual),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue