@@ -2,6 +2,7 @@ use crate::ty::{self, Binder, Ty, TyCtxt, TypeFlags};
22
33use rustc_data_structures:: fx:: FxHashSet ;
44use rustc_data_structures:: sso:: SsoHashSet ;
5+ use rustc_type_ir:: fold:: TypeFoldable ;
56use std:: ops:: ControlFlow ;
67
78pub use rustc_type_ir:: visit:: { TypeSuperVisitable , TypeVisitable , TypeVisitableExt , TypeVisitor } ;
@@ -109,36 +110,37 @@ impl<'tcx> TyCtxt<'tcx> {
109110 /// variables will also be equated.
110111 pub fn collect_constrained_late_bound_regions < T > (
111112 self ,
112- value : & Binder < ' tcx , T > ,
113+ value : Binder < ' tcx , T > ,
113114 ) -> FxHashSet < ty:: BoundRegionKind >
114115 where
115- T : TypeVisitable < TyCtxt < ' tcx > > ,
116+ T : TypeFoldable < TyCtxt < ' tcx > > ,
116117 {
117118 self . collect_late_bound_regions ( value, true )
118119 }
119120
120121 /// Returns a set of all late-bound regions that appear in `value` anywhere.
121122 pub fn collect_referenced_late_bound_regions < T > (
122123 self ,
123- value : & Binder < ' tcx , T > ,
124+ value : Binder < ' tcx , T > ,
124125 ) -> FxHashSet < ty:: BoundRegionKind >
125126 where
126- T : TypeVisitable < TyCtxt < ' tcx > > ,
127+ T : TypeFoldable < TyCtxt < ' tcx > > ,
127128 {
128129 self . collect_late_bound_regions ( value, false )
129130 }
130131
131132 fn collect_late_bound_regions < T > (
132133 self ,
133- value : & Binder < ' tcx , T > ,
134+ value : Binder < ' tcx , T > ,
134135 just_constrained : bool ,
135136 ) -> FxHashSet < ty:: BoundRegionKind >
136137 where
137- T : TypeVisitable < TyCtxt < ' tcx > > ,
138+ T : TypeFoldable < TyCtxt < ' tcx > > ,
138139 {
139- let mut collector = LateBoundRegionsCollector :: new ( self , just_constrained) ;
140+ let mut collector = LateBoundRegionsCollector :: new ( just_constrained) ;
141+ let value = value. skip_binder ( ) ;
140142 let value = if just_constrained { self . expand_weak_alias_tys ( value) } else { value } ;
141- let result = value. as_ref ( ) . skip_binder ( ) . visit_with ( & mut collector) ;
143+ let result = value. visit_with ( & mut collector) ;
142144 assert ! ( result. is_continue( ) ) ; // should never have stopped early
143145 collector. regions
144146 }
@@ -258,12 +260,8 @@ struct LateBoundRegionsCollector {
258260}
259261
260262impl LateBoundRegionsCollector {
261- fn new ( tcx : TyCtxt < ' tcx > , just_constrained : bool ) -> Self {
262- Self {
263- current_index : ty:: INNERMOST ,
264- regions : Default :: default ( ) ,
265- just_constrained,
266- }
263+ fn new ( just_constrained : bool ) -> Self {
264+ Self { current_index : ty:: INNERMOST , regions : Default :: default ( ) , just_constrained }
267265 }
268266}
269267
@@ -287,7 +285,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for LateBoundRegionsCollector {
287285 return ControlFlow :: Continue ( ( ) ) ;
288286 }
289287 // All weak alias types should've been expanded beforehand.
290- ty:: Alias ( ty:: Weak , alias ) => bug ! ( "unexpected weak alias type" ) ,
288+ ty:: Alias ( ty:: Weak , _ ) => bug ! ( "unexpected weak alias type" ) ,
291289 _ => { }
292290 }
293291 }
0 commit comments