@@ -183,6 +183,12 @@ pub trait TypeFolder<'tcx>: Sized {
183183
184184pub trait TypeVisitor < ' tcx > : Sized {
185185 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 > ;
186192
187193 fn visit_binder < T : TypeFoldable < ' tcx > > ( & mut self , t : & Binder < T > ) -> ControlFlow < Self :: BreakTy > {
188194 t. super_visit_with ( self )
@@ -292,7 +298,8 @@ impl<'tcx> TyCtxt<'tcx> {
292298 value : & impl TypeFoldable < ' tcx > ,
293299 callback : impl FnMut ( ty:: Region < ' tcx > ) -> bool ,
294300 ) -> bool {
295- struct RegionVisitor < F > {
301+ struct RegionVisitor < ' tcx , F > {
302+ tcx : TyCtxt < ' tcx > ,
296303 /// The index of a binder *just outside* the things we have
297304 /// traversed. If we encounter a bound region bound by this
298305 /// binder or one outer to it, it appears free. Example:
@@ -314,12 +321,16 @@ impl<'tcx> TyCtxt<'tcx> {
314321 callback : F ,
315322 }
316323
317- impl < ' tcx , F > TypeVisitor < ' tcx > for RegionVisitor < F >
324+ impl < ' tcx , F > TypeVisitor < ' tcx > for RegionVisitor < ' tcx , F >
318325 where
319326 F : FnMut ( ty:: Region < ' tcx > ) -> bool ,
320327 {
321328 type BreakTy = ( ) ;
322329
330+ fn tcx_for_anon_const_substs ( & self ) -> TyCtxt < ' tcx > {
331+ self . tcx
332+ }
333+
323334 fn visit_binder < T : TypeFoldable < ' tcx > > (
324335 & mut self ,
325336 t : & Binder < T > ,
@@ -355,7 +366,9 @@ impl<'tcx> TyCtxt<'tcx> {
355366 }
356367 }
357368
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 ( )
359372 }
360373}
361374
@@ -655,7 +668,7 @@ impl<'tcx> TyCtxt<'tcx> {
655668 where
656669 T : TypeFoldable < ' tcx > ,
657670 {
658- let mut collector = LateBoundRegionsCollector :: new ( just_constraint) ;
671+ let mut collector = LateBoundRegionsCollector :: new ( self , just_constraint) ;
659672 let result = value. as_ref ( ) . skip_binder ( ) . visit_with ( & mut collector) ;
660673 assert ! ( result. is_continue( ) ) ; // should never have stopped early
661674 collector. regions
@@ -830,6 +843,10 @@ struct HasEscapingVarsVisitor {
830843impl < ' tcx > TypeVisitor < ' tcx > for HasEscapingVarsVisitor {
831844 type BreakTy = FoundEscapingVars ;
832845
846+ fn tcx_for_anon_const_substs ( & self ) -> TyCtxt < ' tcx > {
847+ bug ! ( "tcx_for_anon_const_substs called for HasEscpaingVarsVisitor" ) ;
848+ }
849+
833850 fn visit_binder < T : TypeFoldable < ' tcx > > ( & mut self , t : & Binder < T > ) -> ControlFlow < Self :: BreakTy > {
834851 self . outer_index . shift_in ( 1 ) ;
835852 let result = t. super_visit_with ( self ) ;
@@ -897,6 +914,9 @@ struct HasTypeFlagsVisitor {
897914
898915impl < ' tcx > TypeVisitor < ' tcx > for HasTypeFlagsVisitor {
899916 type BreakTy = FoundFlags ;
917+ fn tcx_for_anon_const_substs ( & self ) -> TyCtxt < ' tcx > {
918+ bug ! ( "tcx_for_anon_const_substs called for HasTypeFlagsVisitor" ) ;
919+ }
900920
901921 #[ inline]
902922 fn visit_ty ( & mut self , t : Ty < ' _ > ) -> ControlFlow < Self :: BreakTy > {
@@ -951,7 +971,8 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
951971
952972/// Collects all the late-bound regions at the innermost binding level
953973/// into a hash set.
954- struct LateBoundRegionsCollector {
974+ struct LateBoundRegionsCollector < ' tcx > {
975+ tcx : TyCtxt < ' tcx > ,
955976 current_index : ty:: DebruijnIndex ,
956977 regions : FxHashSet < ty:: BoundRegionKind > ,
957978
@@ -965,17 +986,22 @@ struct LateBoundRegionsCollector {
965986 just_constrained : bool ,
966987}
967988
968- impl LateBoundRegionsCollector {
969- fn new ( just_constrained : bool ) -> Self {
989+ impl LateBoundRegionsCollector < ' tcx > {
990+ fn new ( tcx : TyCtxt < ' tcx > , just_constrained : bool ) -> Self {
970991 LateBoundRegionsCollector {
992+ tcx,
971993 current_index : ty:: INNERMOST ,
972994 regions : Default :: default ( ) ,
973995 just_constrained,
974996 }
975997 }
976998}
977999
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+
9791005 fn visit_binder < T : TypeFoldable < ' tcx > > ( & mut self , t : & Binder < T > ) -> ControlFlow < Self :: BreakTy > {
9801006 self . current_index . shift_in ( 1 ) ;
9811007 let result = t. super_visit_with ( self ) ;
0 commit comments