@@ -11,6 +11,7 @@ use rustc_index::bit_set::BitMatrix;
1111use rustc_index:: { Idx , IndexVec } ;
1212use rustc_macros:: { HashStable , TyDecodable , TyEncodable , TypeFoldable , TypeVisitable } ;
1313use rustc_span:: { Span , Symbol } ;
14+ use rustc_type_ir:: fold:: TypeFoldable ;
1415use smallvec:: SmallVec ;
1516
1617use super :: { ConstValue , SourceInfo } ;
@@ -291,39 +292,37 @@ pub enum ClosureOutlivesSubject<'tcx> {
291292 /// Subject is a type, typically a type parameter, but could also
292293 /// be a projection. Indicates a requirement like `T: 'a` being
293294 /// passed to the caller, where the type here is `T`.
294- Ty ( ClosureOutlivesSubjectTy < ' tcx > ) ,
295+ Ty ( InClosureRequirement < Ty < ' tcx > > ) ,
295296
296297 /// Subject is a free region from the closure. Indicates a requirement
297298 /// like `'a: 'b` being passed to the caller; the region here is `'a`.
298299 Region ( ty:: RegionVid ) ,
299300}
300301
301- /// Represents a `ty::Ty` for use in [`ClosureOutlivesSubject`].
302- ///
303- /// This abstraction is necessary because the type may include `ReVar` regions,
304- /// which is what we use internally within NLL code, and they can't be used in
305- /// a query response.
302+ /// Used for types in `ClosureOutlivesRequirements` which may refer to external
303+ /// regions. This is necessary as they are represented using `ReVar` which must
304+ /// not be used in a query response.
306305///
307306/// DO NOT implement `TypeVisitable` or `TypeFoldable` traits, because this
308307/// type is not recognized as a binder for late-bound region.
309308#[ derive( Copy , Clone , Debug , TyEncodable , TyDecodable , HashStable ) ]
310- pub struct ClosureOutlivesSubjectTy < ' tcx > {
311- inner : Ty < ' tcx > ,
309+ pub struct InClosureRequirement < T > {
310+ inner : T ,
312311}
313312
314- impl < ' tcx > ClosureOutlivesSubjectTy < ' tcx > {
313+ impl < ' tcx , T : TypeFoldable < TyCtxt < ' tcx > > > InClosureRequirement < T > {
315314 /// All regions of `ty` must be of kind `ReVar` and must represent
316315 /// universal regions *external* to the closure.
317- pub fn bind ( tcx : TyCtxt < ' tcx > , ty : Ty < ' tcx > ) -> Self {
318- let inner = fold_regions ( tcx, ty , |r, depth| match r. kind ( ) {
316+ pub fn bind ( tcx : TyCtxt < ' tcx > , value : T ) -> Self {
317+ let inner = fold_regions ( tcx, value , |r, depth| match r. kind ( ) {
319318 ty:: ReVar ( vid) => {
320319 let br = ty:: BoundRegion {
321320 var : ty:: BoundVar :: new ( vid. index ( ) ) ,
322321 kind : ty:: BoundRegionKind :: Anon ,
323322 } ;
324323 ty:: Region :: new_bound ( tcx, depth, br)
325324 }
326- _ => bug ! ( "unexpected region in ClosureOutlivesSubjectTy : {r:?}" ) ,
325+ _ => bug ! ( "unexpected region in closure requirement : {r:?}" ) ,
327326 } ) ;
328327
329328 Self { inner }
@@ -333,7 +332,7 @@ impl<'tcx> ClosureOutlivesSubjectTy<'tcx> {
333332 self ,
334333 tcx : TyCtxt < ' tcx > ,
335334 mut map : impl FnMut ( ty:: RegionVid ) -> ty:: Region < ' tcx > ,
336- ) -> Ty < ' tcx > {
335+ ) -> T {
337336 fold_regions ( tcx, self . inner , |r, depth| match r. kind ( ) {
338337 ty:: ReBound ( debruijn, br) => {
339338 debug_assert_eq ! ( debruijn, depth) ;
0 commit comments