@@ -152,11 +152,14 @@ enum Scope<'a> {
152152 s : ScopeRef < ' a > ,
153153 } ,
154154
155- /// Resolve the lifetimes in the bounds to the lifetime defs in the generics.
156- /// `fn foo<'a>() -> impl MyTrait<'a> { ... }` desugars to
155+ /// Remap lifetimes that appear in opaque types to fresh lifetime parameters. Given:
156+ /// `fn foo<'a>() -> impl MyTrait<'a> { ... }`
157+ ///
158+ /// HIR tells us that `'a` refer to the lifetime bound on `foo`.
159+ /// However, typeck and borrowck for opaques are work based on using a new generics type.
157160 /// `type MyAnonTy<'b> = impl MyTrait<'b>;`
158- /// ^ ^ this gets resolved in the scope of
159- /// the opaque_ty generics
161+ ///
162+ /// This scope collects the mapping `'a -> 'b`.
160163 Opaque {
161164 /// The opaque type we are traversing.
162165 def_id : LocalDefId ,
@@ -547,11 +550,11 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
547550 }
548551 }
549552
550- /// Resolve the lifetimes that are applied to the opaque type.
551- /// These are resolved in the current scope .
552- /// `fn foo<'a>() -> impl MyTrait<'a> { ... }` desugars to
553- /// `fn foo<'a>() -> MyAnonTy<'a> { ... }`
554- /// ^ ^this gets resolved in the current scope
553+ /// Resolve the lifetimes inside the opaque type, and save them into
554+ /// `opaque_captured_lifetimes` .
555+ ///
556+ /// This method has special handling for opaques that capture all lifetimes,
557+ /// like async desugaring.
555558 #[ instrument( level = "debug" , skip( self ) ) ]
556559 fn visit_opaque_ty ( & mut self , opaque : & ' tcx rustc_hir:: OpaqueTy < ' tcx > ) {
557560 let mut captures = FxIndexMap :: default ( ) ;
@@ -815,9 +818,6 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
815818 } ;
816819 self . with ( scope, |this| this. visit_ty ( mt. ty ) ) ;
817820 }
818- hir:: TyKind :: OpaqueDef ( opaque_ty) => {
819- self . visit_opaque_ty ( opaque_ty) ;
820- }
821821 _ => intravisit:: walk_ty ( self , ty) ,
822822 }
823823 }
0 commit comments