@@ -183,6 +183,12 @@ pub trait TypeFolder<'tcx>: Sized {
183
183
184
184
pub trait TypeVisitor < ' tcx > : Sized {
185
185
type BreakTy = !;
186
+ /// Supplies the `tcx` for an unevaluated anonymous constant in case its default substs
187
+ /// are not yet supplied.
188
+ ///
189
+ /// Visitors which do not look into these substs may leave this unimplemented, so be
190
+ /// careful when calling this method elsewhere.
191
+ fn tcx_for_anon_const_substs < ' a > ( & ' a self ) -> TyCtxt < ' tcx > ;
186
192
187
193
fn visit_binder < T : TypeFoldable < ' tcx > > ( & mut self , t : & Binder < T > ) -> ControlFlow < Self :: BreakTy > {
188
194
t. super_visit_with ( self )
@@ -292,7 +298,8 @@ impl<'tcx> TyCtxt<'tcx> {
292
298
value : & impl TypeFoldable < ' tcx > ,
293
299
callback : impl FnMut ( ty:: Region < ' tcx > ) -> bool ,
294
300
) -> bool {
295
- struct RegionVisitor < F > {
301
+ struct RegionVisitor < ' tcx , F > {
302
+ tcx : TyCtxt < ' tcx > ,
296
303
/// The index of a binder *just outside* the things we have
297
304
/// traversed. If we encounter a bound region bound by this
298
305
/// binder or one outer to it, it appears free. Example:
@@ -314,12 +321,16 @@ impl<'tcx> TyCtxt<'tcx> {
314
321
callback : F ,
315
322
}
316
323
317
- impl < ' tcx , F > TypeVisitor < ' tcx > for RegionVisitor < F >
324
+ impl < ' tcx , F > TypeVisitor < ' tcx > for RegionVisitor < ' tcx , F >
318
325
where
319
326
F : FnMut ( ty:: Region < ' tcx > ) -> bool ,
320
327
{
321
328
type BreakTy = ( ) ;
322
329
330
+ fn tcx_for_anon_const_substs ( & self ) -> TyCtxt < ' tcx > {
331
+ self . tcx
332
+ }
333
+
323
334
fn visit_binder < T : TypeFoldable < ' tcx > > (
324
335
& mut self ,
325
336
t : & Binder < T > ,
@@ -355,7 +366,9 @@ impl<'tcx> TyCtxt<'tcx> {
355
366
}
356
367
}
357
368
358
- value. visit_with ( & mut RegionVisitor { outer_index : ty:: INNERMOST , callback } ) . is_break ( )
369
+ value
370
+ . visit_with ( & mut RegionVisitor { tcx : self , outer_index : ty:: INNERMOST , callback } )
371
+ . is_break ( )
359
372
}
360
373
}
361
374
@@ -655,7 +668,7 @@ impl<'tcx> TyCtxt<'tcx> {
655
668
where
656
669
T : TypeFoldable < ' tcx > ,
657
670
{
658
- let mut collector = LateBoundRegionsCollector :: new ( just_constraint) ;
671
+ let mut collector = LateBoundRegionsCollector :: new ( self , just_constraint) ;
659
672
let result = value. as_ref ( ) . skip_binder ( ) . visit_with ( & mut collector) ;
660
673
assert ! ( result. is_continue( ) ) ; // should never have stopped early
661
674
collector. regions
@@ -830,6 +843,10 @@ struct HasEscapingVarsVisitor {
830
843
impl < ' tcx > TypeVisitor < ' tcx > for HasEscapingVarsVisitor {
831
844
type BreakTy = FoundEscapingVars ;
832
845
846
+ fn tcx_for_anon_const_substs ( & self ) -> TyCtxt < ' tcx > {
847
+ bug ! ( "tcx_for_anon_const_substs called for HasEscpaingVarsVisitor" ) ;
848
+ }
849
+
833
850
fn visit_binder < T : TypeFoldable < ' tcx > > ( & mut self , t : & Binder < T > ) -> ControlFlow < Self :: BreakTy > {
834
851
self . outer_index . shift_in ( 1 ) ;
835
852
let result = t. super_visit_with ( self ) ;
@@ -897,6 +914,9 @@ struct HasTypeFlagsVisitor {
897
914
898
915
impl < ' tcx > TypeVisitor < ' tcx > for HasTypeFlagsVisitor {
899
916
type BreakTy = FoundFlags ;
917
+ fn tcx_for_anon_const_substs ( & self ) -> TyCtxt < ' tcx > {
918
+ bug ! ( "tcx_for_anon_const_substs called for HasTypeFlagsVisitor" ) ;
919
+ }
900
920
901
921
#[ inline]
902
922
fn visit_ty ( & mut self , t : Ty < ' _ > ) -> ControlFlow < Self :: BreakTy > {
@@ -951,7 +971,8 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
951
971
952
972
/// Collects all the late-bound regions at the innermost binding level
953
973
/// into a hash set.
954
- struct LateBoundRegionsCollector {
974
+ struct LateBoundRegionsCollector < ' tcx > {
975
+ tcx : TyCtxt < ' tcx > ,
955
976
current_index : ty:: DebruijnIndex ,
956
977
regions : FxHashSet < ty:: BoundRegionKind > ,
957
978
@@ -965,17 +986,22 @@ struct LateBoundRegionsCollector {
965
986
just_constrained : bool ,
966
987
}
967
988
968
- impl LateBoundRegionsCollector {
969
- fn new ( just_constrained : bool ) -> Self {
989
+ impl LateBoundRegionsCollector < ' tcx > {
990
+ fn new ( tcx : TyCtxt < ' tcx > , just_constrained : bool ) -> Self {
970
991
LateBoundRegionsCollector {
992
+ tcx,
971
993
current_index : ty:: INNERMOST ,
972
994
regions : Default :: default ( ) ,
973
995
just_constrained,
974
996
}
975
997
}
976
998
}
977
999
978
- impl < ' tcx > TypeVisitor < ' tcx > for LateBoundRegionsCollector {
1000
+ impl < ' tcx > TypeVisitor < ' tcx > for LateBoundRegionsCollector < ' tcx > {
1001
+ fn tcx_for_anon_const_substs ( & self ) -> TyCtxt < ' tcx > {
1002
+ self . tcx
1003
+ }
1004
+
979
1005
fn visit_binder < T : TypeFoldable < ' tcx > > ( & mut self , t : & Binder < T > ) -> ControlFlow < Self :: BreakTy > {
980
1006
self . current_index . shift_in ( 1 ) ;
981
1007
let result = t. super_visit_with ( self ) ;
0 commit comments