@@ -189,6 +189,12 @@ pub trait TypeFolder<'tcx>: Sized {
189189
190190pub trait TypeVisitor < ' tcx > : Sized {
191191 type BreakTy = !;
192+ /// Supplies the `tcx` for an unevaluated anonymous constant in case its default substs
193+ /// are not yet supplied.
194+ ///
195+ /// Visitors which do not look into these substs may leave this unimplemented, so be
196+ /// careful when calling this method elsewhere.
197+ fn tcx_for_anon_const_substs < ' a > ( & ' a self ) -> TyCtxt < ' tcx > ;
192198
193199 fn visit_binder < T : TypeFoldable < ' tcx > > (
194200 & mut self ,
@@ -301,7 +307,8 @@ impl<'tcx> TyCtxt<'tcx> {
301307 value : & impl TypeFoldable < ' tcx > ,
302308 callback : impl FnMut ( ty:: Region < ' tcx > ) -> bool ,
303309 ) -> bool {
304- struct RegionVisitor < F > {
310+ struct RegionVisitor < ' tcx , F > {
311+ tcx : TyCtxt < ' tcx > ,
305312 /// The index of a binder *just outside* the things we have
306313 /// traversed. If we encounter a bound region bound by this
307314 /// binder or one outer to it, it appears free. Example:
@@ -323,12 +330,16 @@ impl<'tcx> TyCtxt<'tcx> {
323330 callback : F ,
324331 }
325332
326- impl < ' tcx , F > TypeVisitor < ' tcx > for RegionVisitor < F >
333+ impl < ' tcx , F > TypeVisitor < ' tcx > for RegionVisitor < ' tcx , F >
327334 where
328335 F : FnMut ( ty:: Region < ' tcx > ) -> bool ,
329336 {
330337 type BreakTy = ( ) ;
331338
339+ fn tcx_for_anon_const_substs ( & self ) -> TyCtxt < ' tcx > {
340+ self . tcx
341+ }
342+
332343 fn visit_binder < T : TypeFoldable < ' tcx > > (
333344 & mut self ,
334345 t : & Binder < ' tcx , T > ,
@@ -364,7 +375,9 @@ impl<'tcx> TyCtxt<'tcx> {
364375 }
365376 }
366377
367- value. visit_with ( & mut RegionVisitor { outer_index : ty:: INNERMOST , callback } ) . is_break ( )
378+ value
379+ . visit_with ( & mut RegionVisitor { tcx : self , outer_index : ty:: INNERMOST , callback } )
380+ . is_break ( )
368381 }
369382}
370383
@@ -708,7 +721,7 @@ impl<'tcx> TyCtxt<'tcx> {
708721 where
709722 T : TypeFoldable < ' tcx > ,
710723 {
711- let mut collector = LateBoundRegionsCollector :: new ( just_constraint) ;
724+ let mut collector = LateBoundRegionsCollector :: new ( self , just_constraint) ;
712725 let result = value. as_ref ( ) . skip_binder ( ) . visit_with ( & mut collector) ;
713726 assert ! ( result. is_continue( ) ) ; // should never have stopped early
714727 collector. regions
@@ -775,6 +788,10 @@ impl<'tcx> ValidateBoundVars<'tcx> {
775788impl < ' tcx > TypeVisitor < ' tcx > for ValidateBoundVars < ' tcx > {
776789 type BreakTy = ( ) ;
777790
791+ fn tcx_for_anon_const_substs ( & self ) -> TyCtxt < ' tcx > {
792+ bug ! ( "default anon const substs can't contain bound vars" ) ;
793+ }
794+
778795 fn visit_binder < T : TypeFoldable < ' tcx > > (
779796 & mut self ,
780797 t : & Binder < ' tcx , T > ,
@@ -989,6 +1006,10 @@ struct HasEscapingVarsVisitor {
9891006impl < ' tcx > TypeVisitor < ' tcx > for HasEscapingVarsVisitor {
9901007 type BreakTy = FoundEscapingVars ;
9911008
1009+ fn tcx_for_anon_const_substs ( & self ) -> TyCtxt < ' tcx > {
1010+ bug ! ( "tcx_for_anon_const_substs called for HasEscpaingVarsVisitor" ) ;
1011+ }
1012+
9921013 fn visit_binder < T : TypeFoldable < ' tcx > > (
9931014 & mut self ,
9941015 t : & Binder < ' tcx , T > ,
@@ -1059,6 +1080,9 @@ struct HasTypeFlagsVisitor {
10591080
10601081impl < ' tcx > TypeVisitor < ' tcx > for HasTypeFlagsVisitor {
10611082 type BreakTy = FoundFlags ;
1083+ fn tcx_for_anon_const_substs ( & self ) -> TyCtxt < ' tcx > {
1084+ bug ! ( "tcx_for_anon_const_substs called for HasTypeFlagsVisitor" ) ;
1085+ }
10621086
10631087 #[ inline]
10641088 fn visit_ty ( & mut self , t : Ty < ' _ > ) -> ControlFlow < Self :: BreakTy > {
@@ -1113,7 +1137,8 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
11131137
11141138/// Collects all the late-bound regions at the innermost binding level
11151139/// into a hash set.
1116- struct LateBoundRegionsCollector {
1140+ struct LateBoundRegionsCollector < ' tcx > {
1141+ tcx : TyCtxt < ' tcx > ,
11171142 current_index : ty:: DebruijnIndex ,
11181143 regions : FxHashSet < ty:: BoundRegionKind > ,
11191144
@@ -1127,17 +1152,22 @@ struct LateBoundRegionsCollector {
11271152 just_constrained : bool ,
11281153}
11291154
1130- impl LateBoundRegionsCollector {
1131- fn new ( just_constrained : bool ) -> Self {
1155+ impl LateBoundRegionsCollector < ' tcx > {
1156+ fn new ( tcx : TyCtxt < ' tcx > , just_constrained : bool ) -> Self {
11321157 LateBoundRegionsCollector {
1158+ tcx,
11331159 current_index : ty:: INNERMOST ,
11341160 regions : Default :: default ( ) ,
11351161 just_constrained,
11361162 }
11371163 }
11381164}
11391165
1140- impl < ' tcx > TypeVisitor < ' tcx > for LateBoundRegionsCollector {
1166+ impl < ' tcx > TypeVisitor < ' tcx > for LateBoundRegionsCollector < ' tcx > {
1167+ fn tcx_for_anon_const_substs ( & self ) -> TyCtxt < ' tcx > {
1168+ self . tcx
1169+ }
1170+
11411171 fn visit_binder < T : TypeFoldable < ' tcx > > (
11421172 & mut self ,
11431173 t : & Binder < ' tcx , T > ,
0 commit comments