about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-02-02 19:34:07 +0100
committerGitHub <noreply@github.com>2022-02-02 19:34:07 +0100
commit3388e6d9fda3d2bd637b35bbcd71b18d28a026b7 (patch)
treeabb103be7dd3844bc27b6ac1a5c118447341c54d /compiler/rustc_borrowck/src
parent799bded9b44fd59b4647d4e2087b8d336f573bae (diff)
parent670f5c6ef385f251df5cd7bcba9e8039a80bdb4d (diff)
downloadrust-3388e6d9fda3d2bd637b35bbcd71b18d28a026b7.tar.gz
rust-3388e6d9fda3d2bd637b35bbcd71b18d28a026b7.zip
Rollup merge of #93590 - est31:let_else, r=lcnr
More let_else adoptions

Continuation of #89933, #91018, #91481, #93046.
Diffstat (limited to 'compiler/rustc_borrowck/src')
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/region_name.rs137
-rw-r--r--compiler/rustc_borrowck/src/lib.rs5
2 files changed, 67 insertions, 75 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs
index 01cc72121c7..3409f14c98b 100644
--- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs
@@ -311,43 +311,39 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
                 ty::BoundRegionKind::BrEnv => {
                     let def_ty = self.regioncx.universal_regions().defining_ty;
 
-                    if let DefiningTy::Closure(_, substs) = def_ty {
-                        let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) =
-                            tcx.hir().expect_expr(self.mir_hir_id()).kind
-                        {
-                            span
-                        } else {
-                            bug!("Closure is not defined by a closure expr");
-                        };
-                        let region_name = self.synthesize_region_name();
-
-                        let closure_kind_ty = substs.as_closure().kind_ty();
-                        let note = match closure_kind_ty.to_opt_closure_kind() {
-                            Some(ty::ClosureKind::Fn) => {
-                                "closure implements `Fn`, so references to captured variables \
-                                 can't escape the closure"
-                            }
-                            Some(ty::ClosureKind::FnMut) => {
-                                "closure implements `FnMut`, so references to captured variables \
-                                 can't escape the closure"
-                            }
-                            Some(ty::ClosureKind::FnOnce) => {
-                                bug!("BrEnv in a `FnOnce` closure");
-                            }
-                            None => bug!("Closure kind not inferred in borrow check"),
-                        };
-
-                        Some(RegionName {
-                            name: region_name,
-                            source: RegionNameSource::SynthesizedFreeEnvRegion(
-                                args_span,
-                                note.to_string(),
-                            ),
-                        })
-                    } else {
+                    let DefiningTy::Closure(_, substs) = def_ty else {
                         // Can't have BrEnv in functions, constants or generators.
                         bug!("BrEnv outside of closure.");
-                    }
+                    };
+                    let hir::ExprKind::Closure(_, _, _, args_span, _) =
+                        tcx.hir().expect_expr(self.mir_hir_id()).kind else {
+                        bug!("Closure is not defined by a closure expr");
+                    };
+                    let region_name = self.synthesize_region_name();
+
+                    let closure_kind_ty = substs.as_closure().kind_ty();
+                    let note = match closure_kind_ty.to_opt_closure_kind() {
+                        Some(ty::ClosureKind::Fn) => {
+                            "closure implements `Fn`, so references to captured variables \
+                                can't escape the closure"
+                        }
+                        Some(ty::ClosureKind::FnMut) => {
+                            "closure implements `FnMut`, so references to captured variables \
+                                can't escape the closure"
+                        }
+                        Some(ty::ClosureKind::FnOnce) => {
+                            bug!("BrEnv in a `FnOnce` closure");
+                        }
+                        None => bug!("Closure kind not inferred in borrow check"),
+                    };
+
+                    Some(RegionName {
+                        name: region_name,
+                        source: RegionNameSource::SynthesizedFreeEnvRegion(
+                            args_span,
+                            note.to_string(),
+                        ),
+                    })
                 }
 
                 ty::BoundRegionKind::BrAnon(_) => None,
@@ -765,48 +761,45 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
     fn get_future_inner_return_ty(&self, hir_ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> {
         let hir = self.infcx.tcx.hir();
 
-        if let hir::TyKind::OpaqueDef(id, _) = hir_ty.kind {
-            let opaque_ty = hir.item(id);
-            if let hir::ItemKind::OpaqueTy(hir::OpaqueTy {
-                bounds:
-                    [
-                        hir::GenericBound::LangItemTrait(
-                            hir::LangItem::Future,
-                            _,
-                            _,
-                            hir::GenericArgs {
-                                bindings:
-                                    [
-                                        hir::TypeBinding {
-                                            ident: Ident { name: sym::Output, .. },
-                                            kind:
-                                                hir::TypeBindingKind::Equality {
-                                                    term: hir::Term::Ty(ty),
-                                                },
-                                            ..
-                                        },
-                                    ],
-                                ..
-                            },
-                        ),
-                    ],
-                ..
-            }) = opaque_ty.kind
-            {
-                ty
-            } else {
-                span_bug!(
-                    hir_ty.span,
-                    "bounds from lowered return type of async fn did not match expected format: {:?}",
-                    opaque_ty
-                );
-            }
-        } else {
+        let hir::TyKind::OpaqueDef(id, _) = hir_ty.kind else {
             span_bug!(
                 hir_ty.span,
                 "lowered return type of async fn is not OpaqueDef: {:?}",
                 hir_ty
             );
+        };
+        let opaque_ty = hir.item(id);
+        if let hir::ItemKind::OpaqueTy(hir::OpaqueTy {
+            bounds:
+                [
+                    hir::GenericBound::LangItemTrait(
+                        hir::LangItem::Future,
+                        _,
+                        _,
+                        hir::GenericArgs {
+                            bindings:
+                                [
+                                    hir::TypeBinding {
+                                        ident: Ident { name: sym::Output, .. },
+                                        kind:
+                                            hir::TypeBindingKind::Equality { term: hir::Term::Ty(ty) },
+                                        ..
+                                    },
+                                ],
+                            ..
+                        },
+                    ),
+                ],
+            ..
+        }) = opaque_ty.kind
+        {
+            ty
+        } else {
+            span_bug!(
+                hir_ty.span,
+                "bounds from lowered return type of async fn did not match expected format: {:?}",
+                opaque_ty
+            );
         }
     }
 
diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs
index c288cc96990..5597a8b0915 100644
--- a/compiler/rustc_borrowck/src/lib.rs
+++ b/compiler/rustc_borrowck/src/lib.rs
@@ -1427,9 +1427,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
                             bug!("temporary should be initialized exactly once")
                         };
 
-                        let loc = match init.location {
-                            InitLocation::Statement(stmt) => stmt,
-                            _ => bug!("temporary initialized in arguments"),
+                        let InitLocation::Statement(loc) = init.location else {
+                            bug!("temporary initialized in arguments")
                         };
 
                         let body = self.body;