@@ -311,43 +311,39 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
311
311
ty:: BoundRegionKind :: BrEnv => {
312
312
let def_ty = self . regioncx . universal_regions ( ) . defining_ty ;
313
313
314
- if let DefiningTy :: Closure ( _, substs) = def_ty {
315
- let args_span = if let hir:: ExprKind :: Closure ( _, _, _, span, _) =
316
- tcx. hir ( ) . expect_expr ( self . mir_hir_id ( ) ) . kind
317
- {
318
- span
319
- } else {
320
- bug ! ( "Closure is not defined by a closure expr" ) ;
321
- } ;
322
- let region_name = self . synthesize_region_name ( ) ;
323
-
324
- let closure_kind_ty = substs. as_closure ( ) . kind_ty ( ) ;
325
- let note = match closure_kind_ty. to_opt_closure_kind ( ) {
326
- Some ( ty:: ClosureKind :: Fn ) => {
327
- "closure implements `Fn`, so references to captured variables \
328
- can't escape the closure"
329
- }
330
- Some ( ty:: ClosureKind :: FnMut ) => {
331
- "closure implements `FnMut`, so references to captured variables \
332
- can't escape the closure"
333
- }
334
- Some ( ty:: ClosureKind :: FnOnce ) => {
335
- bug ! ( "BrEnv in a `FnOnce` closure" ) ;
336
- }
337
- None => bug ! ( "Closure kind not inferred in borrow check" ) ,
338
- } ;
339
-
340
- Some ( RegionName {
341
- name : region_name,
342
- source : RegionNameSource :: SynthesizedFreeEnvRegion (
343
- args_span,
344
- note. to_string ( ) ,
345
- ) ,
346
- } )
347
- } else {
314
+ let DefiningTy :: Closure ( _, substs) = def_ty else {
348
315
// Can't have BrEnv in functions, constants or generators.
349
316
bug ! ( "BrEnv outside of closure." ) ;
350
- }
317
+ } ;
318
+ let hir:: ExprKind :: Closure ( _, _, _, args_span, _) =
319
+ tcx. hir ( ) . expect_expr ( self . mir_hir_id ( ) ) . kind else {
320
+ bug ! ( "Closure is not defined by a closure expr" ) ;
321
+ } ;
322
+ let region_name = self . synthesize_region_name ( ) ;
323
+
324
+ let closure_kind_ty = substs. as_closure ( ) . kind_ty ( ) ;
325
+ let note = match closure_kind_ty. to_opt_closure_kind ( ) {
326
+ Some ( ty:: ClosureKind :: Fn ) => {
327
+ "closure implements `Fn`, so references to captured variables \
328
+ can't escape the closure"
329
+ }
330
+ Some ( ty:: ClosureKind :: FnMut ) => {
331
+ "closure implements `FnMut`, so references to captured variables \
332
+ can't escape the closure"
333
+ }
334
+ Some ( ty:: ClosureKind :: FnOnce ) => {
335
+ bug ! ( "BrEnv in a `FnOnce` closure" ) ;
336
+ }
337
+ None => bug ! ( "Closure kind not inferred in borrow check" ) ,
338
+ } ;
339
+
340
+ Some ( RegionName {
341
+ name : region_name,
342
+ source : RegionNameSource :: SynthesizedFreeEnvRegion (
343
+ args_span,
344
+ note. to_string ( ) ,
345
+ ) ,
346
+ } )
351
347
}
352
348
353
349
ty:: BoundRegionKind :: BrAnon ( _) => None ,
@@ -765,48 +761,45 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
765
761
fn get_future_inner_return_ty ( & self , hir_ty : & ' tcx hir:: Ty < ' tcx > ) -> & ' tcx hir:: Ty < ' tcx > {
766
762
let hir = self . infcx . tcx . hir ( ) ;
767
763
768
- if let hir:: TyKind :: OpaqueDef ( id, _) = hir_ty. kind {
769
- let opaque_ty = hir. item ( id) ;
770
- if let hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy {
771
- bounds :
772
- [
773
- hir:: GenericBound :: LangItemTrait (
774
- hir:: LangItem :: Future ,
775
- _,
776
- _,
777
- hir:: GenericArgs {
778
- bindings :
779
- [
780
- hir:: TypeBinding {
781
- ident : Ident { name : sym:: Output , .. } ,
782
- kind :
783
- hir:: TypeBindingKind :: Equality {
784
- term : hir:: Term :: Ty ( ty) ,
785
- } ,
786
- ..
787
- } ,
788
- ] ,
789
- ..
790
- } ,
791
- ) ,
792
- ] ,
793
- ..
794
- } ) = opaque_ty. kind
795
- {
796
- ty
797
- } else {
798
- span_bug ! (
799
- hir_ty. span,
800
- "bounds from lowered return type of async fn did not match expected format: {:?}" ,
801
- opaque_ty
802
- ) ;
803
- }
804
- } else {
764
+ let hir:: TyKind :: OpaqueDef ( id, _) = hir_ty. kind else {
805
765
span_bug ! (
806
766
hir_ty. span,
807
767
"lowered return type of async fn is not OpaqueDef: {:?}" ,
808
768
hir_ty
809
769
) ;
770
+ } ;
771
+ let opaque_ty = hir. item ( id) ;
772
+ if let hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy {
773
+ bounds :
774
+ [
775
+ hir:: GenericBound :: LangItemTrait (
776
+ hir:: LangItem :: Future ,
777
+ _,
778
+ _,
779
+ hir:: GenericArgs {
780
+ bindings :
781
+ [
782
+ hir:: TypeBinding {
783
+ ident : Ident { name : sym:: Output , .. } ,
784
+ kind :
785
+ hir:: TypeBindingKind :: Equality { term : hir:: Term :: Ty ( ty) } ,
786
+ ..
787
+ } ,
788
+ ] ,
789
+ ..
790
+ } ,
791
+ ) ,
792
+ ] ,
793
+ ..
794
+ } ) = opaque_ty. kind
795
+ {
796
+ ty
797
+ } else {
798
+ span_bug ! (
799
+ hir_ty. span,
800
+ "bounds from lowered return type of async fn did not match expected format: {:?}" ,
801
+ opaque_ty
802
+ ) ;
810
803
}
811
804
}
812
805
0 commit comments