@@ -11,6 +11,7 @@ use rustc_index::bit_set::BitMatrix;
11
11
use rustc_index:: { Idx , IndexVec } ;
12
12
use rustc_macros:: { HashStable , TyDecodable , TyEncodable , TypeFoldable , TypeVisitable } ;
13
13
use rustc_span:: { Span , Symbol } ;
14
+ use rustc_type_ir:: fold:: TypeFoldable ;
14
15
use smallvec:: SmallVec ;
15
16
16
17
use super :: { ConstValue , SourceInfo } ;
@@ -291,39 +292,37 @@ pub enum ClosureOutlivesSubject<'tcx> {
291
292
/// Subject is a type, typically a type parameter, but could also
292
293
/// be a projection. Indicates a requirement like `T: 'a` being
293
294
/// passed to the caller, where the type here is `T`.
294
- Ty ( ClosureOutlivesSubjectTy < ' tcx > ) ,
295
+ Ty ( InClosureRequirement < Ty < ' tcx > > ) ,
295
296
296
297
/// Subject is a free region from the closure. Indicates a requirement
297
298
/// like `'a: 'b` being passed to the caller; the region here is `'a`.
298
299
Region ( ty:: RegionVid ) ,
299
300
}
300
301
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.
306
305
///
307
306
/// DO NOT implement `TypeVisitable` or `TypeFoldable` traits, because this
308
307
/// type is not recognized as a binder for late-bound region.
309
308
#[ derive( Copy , Clone , Debug , TyEncodable , TyDecodable , HashStable ) ]
310
- pub struct ClosureOutlivesSubjectTy < ' tcx > {
311
- inner : Ty < ' tcx > ,
309
+ pub struct InClosureRequirement < T > {
310
+ inner : T ,
312
311
}
313
312
314
- impl < ' tcx > ClosureOutlivesSubjectTy < ' tcx > {
313
+ impl < ' tcx , T : TypeFoldable < TyCtxt < ' tcx > > > InClosureRequirement < T > {
315
314
/// All regions of `ty` must be of kind `ReVar` and must represent
316
315
/// 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 ( ) {
319
318
ty:: ReVar ( vid) => {
320
319
let br = ty:: BoundRegion {
321
320
var : ty:: BoundVar :: new ( vid. index ( ) ) ,
322
321
kind : ty:: BoundRegionKind :: Anon ,
323
322
} ;
324
323
ty:: Region :: new_bound ( tcx, depth, br)
325
324
}
326
- _ => bug ! ( "unexpected region in ClosureOutlivesSubjectTy : {r:?}" ) ,
325
+ _ => bug ! ( "unexpected region in closure requirement : {r:?}" ) ,
327
326
} ) ;
328
327
329
328
Self { inner }
@@ -333,7 +332,7 @@ impl<'tcx> ClosureOutlivesSubjectTy<'tcx> {
333
332
self ,
334
333
tcx : TyCtxt < ' tcx > ,
335
334
mut map : impl FnMut ( ty:: RegionVid ) -> ty:: Region < ' tcx > ,
336
- ) -> Ty < ' tcx > {
335
+ ) -> T {
337
336
fold_regions ( tcx, self . inner , |r, depth| match r. kind ( ) {
338
337
ty:: ReBound ( debruijn, br) => {
339
338
debug_assert_eq ! ( debruijn, depth) ;
0 commit comments