@@ -452,7 +452,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
452452 intravisit:: walk_item ( this, item)
453453 } ) ;
454454 }
455- hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { .. } ) => {
455+ hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy {
456+ origin : hir:: OpaqueTyOrigin :: TyAlias , ..
457+ } ) => {
456458 // Opaque types are visited when we visit the
457459 // `TyKind::OpaqueDef`, so that they have the lifetimes from
458460 // their parent opaque_ty in scope.
@@ -478,6 +480,37 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
478480 } ) ;
479481 }
480482 }
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+ }
481514 hir:: ItemKind :: TyAlias ( _, ref generics)
482515 | hir:: ItemKind :: Enum ( _, ref generics)
483516 | hir:: ItemKind :: Struct ( _, ref generics)
@@ -604,7 +637,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
604637 // ^ ^ this gets resolved in the scope of
605638 // the opaque_ty generics
606639 let opaque_ty = self . tcx . hir ( ) . item ( item_id) ;
607- let ( generics , bounds ) = match opaque_ty. kind {
640+ match opaque_ty. kind {
608641 hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy {
609642 origin : hir:: OpaqueTyOrigin :: TyAlias ,
610643 ..
@@ -625,10 +658,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
625658 }
626659 hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy {
627660 origin : hir:: OpaqueTyOrigin :: FnReturn ( ..) | hir:: OpaqueTyOrigin :: AsyncFn ( ..) ,
628- ref generics,
629- bounds,
630661 ..
631- } ) => ( generics , bounds ) ,
662+ } ) => { }
632663 ref i => bug ! ( "`impl Trait` pointed to non-opaque type?? {:#?}" , i) ,
633664 } ;
634665
@@ -681,38 +712,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
681712 self . uninsert_lifetime_on_error ( lifetime, def. unwrap ( ) ) ;
682713 }
683714 }
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- } ) ;
716715 }
717716 _ => intravisit:: walk_ty ( self , ty) ,
718717 }
0 commit comments