@@ -452,7 +452,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
452
452
intravisit:: walk_item ( this, item)
453
453
} ) ;
454
454
}
455
- hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { .. } ) => {
455
+ hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy {
456
+ origin : hir:: OpaqueTyOrigin :: TyAlias , ..
457
+ } ) => {
456
458
// Opaque types are visited when we visit the
457
459
// `TyKind::OpaqueDef`, so that they have the lifetimes from
458
460
// their parent opaque_ty in scope.
@@ -478,6 +480,37 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
478
480
} ) ;
479
481
}
480
482
}
483
+ hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy {
484
+ origin : hir:: OpaqueTyOrigin :: FnReturn ( _) | hir:: OpaqueTyOrigin :: AsyncFn ( _) ,
485
+ generics,
486
+ ..
487
+ } ) => {
488
+ // We want to start our early-bound indices at the end of the parent scope,
489
+ // not including any parent `impl Trait`s.
490
+ let mut lifetimes = FxIndexMap :: default ( ) ;
491
+ debug ! ( ?generics. params) ;
492
+ for param in generics. params {
493
+ match param. kind {
494
+ GenericParamKind :: Lifetime { .. } => {
495
+ let ( def_id, reg) = Region :: early ( self . tcx . hir ( ) , & param) ;
496
+ lifetimes. insert ( def_id, reg) ;
497
+ }
498
+ GenericParamKind :: Type { .. } | GenericParamKind :: Const { .. } => { }
499
+ }
500
+ }
501
+
502
+ let scope = Scope :: Binder {
503
+ hir_id : item. hir_id ( ) ,
504
+ lifetimes,
505
+ s : self . scope ,
506
+ scope_type : BinderScopeType :: Normal ,
507
+ where_bound_origin : None ,
508
+ } ;
509
+ self . with ( scope, |this| {
510
+ let scope = Scope :: TraitRefBoundary { s : this. scope } ;
511
+ this. with ( scope, |this| intravisit:: walk_item ( this, item) )
512
+ } ) ;
513
+ }
481
514
hir:: ItemKind :: TyAlias ( _, ref generics)
482
515
| hir:: ItemKind :: Enum ( _, ref generics)
483
516
| hir:: ItemKind :: Struct ( _, ref generics)
@@ -604,7 +637,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
604
637
// ^ ^ this gets resolved in the scope of
605
638
// the opaque_ty generics
606
639
let opaque_ty = self . tcx . hir ( ) . item ( item_id) ;
607
- let ( generics , bounds ) = match opaque_ty. kind {
640
+ match opaque_ty. kind {
608
641
hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy {
609
642
origin : hir:: OpaqueTyOrigin :: TyAlias ,
610
643
..
@@ -625,10 +658,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
625
658
}
626
659
hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy {
627
660
origin : hir:: OpaqueTyOrigin :: FnReturn ( ..) | hir:: OpaqueTyOrigin :: AsyncFn ( ..) ,
628
- ref generics,
629
- bounds,
630
661
..
631
- } ) => ( generics , bounds ) ,
662
+ } ) => { }
632
663
ref i => bug ! ( "`impl Trait` pointed to non-opaque type?? {:#?}" , i) ,
633
664
} ;
634
665
@@ -681,38 +712,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
681
712
self . uninsert_lifetime_on_error ( lifetime, def. unwrap ( ) ) ;
682
713
}
683
714
}
684
-
685
- // We want to start our early-bound indices at the end of the parent scope,
686
- // not including any parent `impl Trait`s.
687
- let mut lifetimes = FxIndexMap :: default ( ) ;
688
- debug ! ( ?generics. params) ;
689
- for param in generics. params {
690
- match param. kind {
691
- GenericParamKind :: Lifetime { .. } => {
692
- let ( def_id, reg) = Region :: early ( self . tcx . hir ( ) , & param) ;
693
- lifetimes. insert ( def_id, reg) ;
694
- }
695
- GenericParamKind :: Type { .. } | GenericParamKind :: Const { .. } => { }
696
- }
697
- }
698
- self . record_late_bound_vars ( ty. hir_id , vec ! [ ] ) ;
699
-
700
- let scope = Scope :: Binder {
701
- hir_id : ty. hir_id ,
702
- lifetimes,
703
- s : self . scope ,
704
- scope_type : BinderScopeType :: Normal ,
705
- where_bound_origin : None ,
706
- } ;
707
- self . with ( scope, |this| {
708
- let scope = Scope :: TraitRefBoundary { s : this. scope } ;
709
- this. with ( scope, |this| {
710
- this. visit_generics ( generics) ;
711
- for bound in bounds {
712
- this. visit_param_bound ( bound) ;
713
- }
714
- } )
715
- } ) ;
716
715
}
717
716
_ => intravisit:: walk_ty ( self , ty) ,
718
717
}
0 commit comments