@@ -152,11 +152,14 @@ enum Scope<'a> {
152
152
s : ScopeRef < ' a > ,
153
153
} ,
154
154
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.
157
160
/// `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`.
160
163
Opaque {
161
164
/// The opaque type we are traversing.
162
165
def_id : LocalDefId ,
@@ -547,11 +550,11 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
547
550
}
548
551
}
549
552
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.
555
558
#[ instrument( level = "debug" , skip( self ) ) ]
556
559
fn visit_opaque_ty ( & mut self , opaque : & ' tcx rustc_hir:: OpaqueTy < ' tcx > ) {
557
560
let mut captures = FxIndexMap :: default ( ) ;
@@ -815,9 +818,6 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
815
818
} ;
816
819
self . with ( scope, |this| this. visit_ty ( mt. ty ) ) ;
817
820
}
818
- hir:: TyKind :: OpaqueDef ( opaque_ty) => {
819
- self . visit_opaque_ty ( opaque_ty) ;
820
- }
821
821
_ => intravisit:: walk_ty ( self , ty) ,
822
822
}
823
823
}
0 commit comments