Adopt let else in more places

This commit is contained in:
est31 2022-02-19 00:48:49 +01:00
parent b8c56fa8c3
commit 2ef8af6619
132 changed files with 539 additions and 881 deletions

View file

@ -18,16 +18,14 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
let error = self.error.as_ref()?;
debug!("try_report_mismatched_static_lifetime {:?}", error);
let (origin, sub, sup) = match error.clone() {
RegionResolutionError::ConcreteFailure(origin, sub, sup) => (origin, sub, sup),
_ => return None,
let RegionResolutionError::ConcreteFailure(origin, sub, sup) = error.clone() else {
return None;
};
if !sub.is_static() {
return None;
}
let cause = match origin {
SubregionOrigin::Subtype(box TypeTrace { ref cause, .. }) => cause,
_ => return None,
let SubregionOrigin::Subtype(box TypeTrace { ref cause, .. }) = origin else {
return None;
};
// If we added a "points at argument expression" obligation, we remove it here, we care
// about the original obligation only.
@ -35,13 +33,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => &*parent_code,
_ => cause.code(),
};
let (parent, impl_def_id) = match code {
ObligationCauseCode::MatchImpl(parent, impl_def_id) => (parent, impl_def_id),
_ => return None,
let ObligationCauseCode::MatchImpl(parent, impl_def_id) = code else {
return None;
};
let binding_span = match *parent.code() {
ObligationCauseCode::BindingObligation(_def_id, binding_span) => binding_span,
_ => return None,
let ObligationCauseCode::BindingObligation(_def_id, binding_span) = *parent.code() else {
return None;
};
let mut err = self.tcx().sess.struct_span_err(cause.span, "incompatible lifetime on type");
// FIXME: we should point at the lifetime
@ -55,12 +51,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
// be as helpful as possible with implicit lifetimes.
// First, let's get the hir self type of the impl
let impl_self_ty = match impl_node {
hir::Node::Item(hir::Item {
kind: hir::ItemKind::Impl(hir::Impl { self_ty, .. }),
..
}) => self_ty,
_ => bug!("Node not an impl."),
let hir::Node::Item(hir::Item {
kind: hir::ItemKind::Impl(hir::Impl { self_ty: impl_self_ty, .. }),
..
}) = impl_node else {
bug!("Node not an impl.");
};
// Next, let's figure out the set of trait objects with implict static bounds

View file

@ -490,14 +490,13 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
let tcx = self.tcx();
// Find the method being called.
let instance = match ty::Instance::resolve(
let Ok(Some(instance)) = ty::Instance::resolve(
tcx,
ctxt.param_env,
ctxt.assoc_item.def_id,
self.infcx.resolve_vars_if_possible(ctxt.substs),
) {
Ok(Some(instance)) => instance,
_ => return false,
) else {
return false;
};
let mut v = TraitObjectVisitor(FxHashSet::default());
@ -505,11 +504,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
// Get the `Ident` of the method being called and the corresponding `impl` (to point at
// `Bar` in `impl Foo for dyn Bar {}` and the definition of the method being called).
let (ident, self_ty) =
match self.get_impl_ident_and_self_ty_from_trait(instance.def_id(), &v.0) {
Some((ident, self_ty)) => (ident, self_ty),
None => return false,
};
let Some((ident, self_ty)) = self.get_impl_ident_and_self_ty_from_trait(instance.def_id(), &v.0) else {
return false;
};
// Find the trait object types in the argument, so we point at *only* the trait object.
self.suggest_constrain_dyn_trait_in_impl(err, &v.0, ident, self_ty)

View file

@ -263,9 +263,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
while let Some(vid) = changes.pop() {
constraints[vid].retain(|&(a_vid, b_vid)| {
let a_region = match *var_values.value(a_vid) {
VarValue::ErrorValue => return false,
VarValue::Value(a_region) => a_region,
let VarValue::Value(a_region) = *var_values.value(a_vid) else {
return false;
};
let b_data = var_values.value_mut(b_vid);
if self.expand_node(a_region, b_vid, b_data) {
@ -485,9 +484,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
let a_data = var_data.value_mut(a_vid);
debug!("contraction: {:?} == {:?}, {:?}", a_vid, a_data, b_region);
let a_region = match *a_data {
VarValue::ErrorValue => continue,
VarValue::Value(a_region) => a_region,
let VarValue::Value(a_region) = *a_data else {
continue;
};
// Do not report these errors immediately: