@@ -116,21 +116,9 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
116
116
pub trait TypeFolder < ' tcx > : Sized {
117
117
fn tcx < ' a > ( & ' a self ) -> & ' a TyCtxt < ' tcx > ;
118
118
119
- /// Invoked by the `super_*` routines when we enter a region
120
- /// binding level (for example, when entering a function
121
- /// signature). This is used by clients that want to track the
122
- /// Debruijn index nesting level.
123
- fn enter_region_binder ( & mut self ) { }
124
-
125
- /// Invoked by the `super_*` routines when we exit a region
126
- /// binding level. This is used by clients that want to
127
- /// track the Debruijn index nesting level.
128
- fn exit_region_binder ( & mut self ) { }
129
-
130
119
fn fold_binder < T > ( & mut self , t : & Binder < T > ) -> Binder < T >
131
120
where T : TypeFoldable < ' tcx >
132
121
{
133
- // FIXME(#20526) this should replace `enter_region_binder`/`exit_region_binder`.
134
122
t. super_fold_with ( self )
135
123
}
136
124
@@ -197,8 +185,9 @@ pub trait TypeFolder<'tcx> : Sized {
197
185
}
198
186
199
187
pub trait TypeVisitor < ' tcx > : Sized {
200
- fn enter_region_binder ( & mut self ) { }
201
- fn exit_region_binder ( & mut self ) { }
188
+ fn visit_binder < T : TypeFoldable < ' tcx > > ( & mut self , t : & Binder < T > ) -> bool {
189
+ t. super_visit_with ( self )
190
+ }
202
191
203
192
fn visit_ty ( & mut self , t : Ty < ' tcx > ) -> bool {
204
193
t. super_visit_with ( self )
@@ -296,12 +285,11 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionFolder<'a, 'tcx>
296
285
{
297
286
fn tcx ( & self ) -> & TyCtxt < ' tcx > { self . tcx }
298
287
299
- fn enter_region_binder ( & mut self ) {
288
+ fn fold_binder < T : TypeFoldable < ' tcx > > ( & mut self , t : & ty :: Binder < T > ) -> ty :: Binder < T > {
300
289
self . current_depth += 1 ;
301
- }
302
-
303
- fn exit_region_binder ( & mut self ) {
290
+ let t = t. super_fold_with ( self ) ;
304
291
self . current_depth -= 1 ;
292
+ t
305
293
}
306
294
307
295
fn fold_region ( & mut self , r : ty:: Region ) -> ty:: Region {
@@ -438,12 +426,11 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionReplacer<'a, 'tcx>
438
426
{
439
427
fn tcx ( & self ) -> & TyCtxt < ' tcx > { self . tcx }
440
428
441
- fn enter_region_binder ( & mut self ) {
429
+ fn fold_binder < T : TypeFoldable < ' tcx > > ( & mut self , t : & ty :: Binder < T > ) -> ty :: Binder < T > {
442
430
self . current_depth += 1 ;
443
- }
444
-
445
- fn exit_region_binder ( & mut self ) {
431
+ let t = t. super_fold_with ( self ) ;
446
432
self . current_depth -= 1 ;
433
+ t
447
434
}
448
435
449
436
fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
@@ -596,12 +583,11 @@ struct HasEscapingRegionsVisitor {
596
583
}
597
584
598
585
impl < ' tcx > TypeVisitor < ' tcx > for HasEscapingRegionsVisitor {
599
- fn enter_region_binder ( & mut self ) {
586
+ fn visit_binder < T : TypeFoldable < ' tcx > > ( & mut self , t : & Binder < T > ) -> bool {
600
587
self . depth += 1 ;
601
- }
602
-
603
- fn exit_region_binder ( & mut self ) {
588
+ let result = t. super_visit_with ( self ) ;
604
589
self . depth -= 1 ;
590
+ result
605
591
}
606
592
607
593
fn visit_ty ( & mut self , t : Ty < ' tcx > ) -> bool {
0 commit comments