diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-02-20 00:37:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-20 00:37:34 +0100 |
| commit | f2d6770f779051f1f5a28451b68784d2103bca32 (patch) | |
| tree | 90ba27b14c38a8ff603d9aef8642a16b58a7f52d /compiler/rustc_infer/src/infer | |
| parent | 7ca1c48bbb6d300bda665a59b7ad226bc71e7be9 (diff) | |
| parent | 2ef8af66196f7cc270a0532ea989f2fc6bc6885d (diff) | |
| download | rust-f2d6770f779051f1f5a28451b68784d2103bca32.tar.gz rust-f2d6770f779051f1f5a28451b68784d2103bca32.zip | |
Rollup merge of #94146 - est31:let_else, r=cjgillot
Adopt let else in more places Continuation of #89933, #91018, #91481, #93046, #93590, #94011. I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This is the biggest of these PRs and handles the changes outside of rustdoc, rustc_typeck, rustc_const_eval, rustc_trait_selection, which were handled in PRs #94139, #94142, #94143, #94144.
Diffstat (limited to 'compiler/rustc_infer/src/infer')
3 files changed, 23 insertions, 33 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mismatched_static_lifetime.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mismatched_static_lifetime.rs index ef4c9c24f3e..2bc2f78261d 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mismatched_static_lifetime.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mismatched_static_lifetime.rs @@ -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 diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs index 625fd864218..8601180842c 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -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) diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index 4e50585ff52..c7b4a96fb78 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -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: |
