@@ -158,11 +158,14 @@ enum Scope<'a> {
158
158
s : ScopeRef < ' a > ,
159
159
} ,
160
160
161
- /// Resolve the lifetimes in the bounds to the lifetime defs in the generics.
162
- /// `fn foo<'a>() -> impl MyTrait<'a> { ... }` desugars to
161
+ /// Remap lifetimes that appear in opaque types to fresh lifetime parameters. Given:
162
+ /// `fn foo<'a>() -> impl MyTrait<'a> { ... }`
163
+ ///
164
+ /// HIR tells us that `'a` refer to the lifetime bound on `foo`.
165
+ /// However, typeck and borrowck for opaques are work based on using a new generics type.
163
166
/// `type MyAnonTy<'b> = impl MyTrait<'b>;`
164
- /// ^ ^ this gets resolved in the scope of
165
- /// the opaque_ty generics
167
+ ///
168
+ /// This scope collects the mapping `'a -> 'b`.
166
169
Opaque {
167
170
/// The opaque type we are traversing.
168
171
def_id : LocalDefId ,
@@ -542,11 +545,11 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
542
545
}
543
546
}
544
547
545
- /// Resolve the lifetimes that are applied to the opaque type.
546
- /// These are resolved in the current scope .
547
- /// `fn foo<'a>() -> impl MyTrait<'a> { ... }` desugars to
548
- /// `fn foo<'a>() -> MyAnonTy<'a> { ... }`
549
- /// ^ ^this gets resolved in the current scope
548
+ /// Resolve the lifetimes inside the opaque type, and save them into
549
+ /// `opaque_captured_lifetimes` .
550
+ ///
551
+ /// This method has special handling for opaques that capture all lifetimes,
552
+ /// like async desugaring.
550
553
#[ instrument( level = "debug" , skip( self ) ) ]
551
554
fn visit_opaque_ty ( & mut self , opaque : & ' tcx rustc_hir:: OpaqueTy < ' tcx > ) {
552
555
let mut captures = FxIndexMap :: default ( ) ;
@@ -809,9 +812,6 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
809
812
} ;
810
813
self . with ( scope, |this| this. visit_ty ( mt. ty ) ) ;
811
814
}
812
- hir:: TyKind :: OpaqueDef ( opaque_ty) => {
813
- self . visit_opaque_ty ( opaque_ty) ;
814
- }
815
815
_ => intravisit:: walk_ty ( self , ty) ,
816
816
}
817
817
}
0 commit comments