@@ -54,7 +54,7 @@ use tracing::{debug, instrument};
54
54
55
55
use crate :: inherent:: * ;
56
56
use crate :: visit:: { TypeVisitable , TypeVisitableExt as _} ;
57
- use crate :: { self as ty, Interner } ;
57
+ use crate :: { self as ty, Interner , TypeFlags } ;
58
58
59
59
#[ cfg( feature = "nightly" ) ]
60
60
type Never = !;
@@ -438,12 +438,12 @@ where
438
438
pub fn fold_regions < I : Interner , T > (
439
439
cx : I ,
440
440
value : T ,
441
- mut f : impl FnMut ( I :: Region , ty:: DebruijnIndex ) -> I :: Region ,
441
+ f : impl FnMut ( I :: Region , ty:: DebruijnIndex ) -> I :: Region ,
442
442
) -> T
443
443
where
444
444
T : TypeFoldable < I > ,
445
445
{
446
- value. fold_with ( & mut RegionFolder :: new ( cx, & mut f) )
446
+ value. fold_with ( & mut RegionFolder :: new ( cx, f) )
447
447
}
448
448
449
449
/// Folds over the substructure of a type, visiting its component
@@ -453,7 +453,7 @@ where
453
453
/// new bound regions which are not visited by this visitors as
454
454
/// they are not free; only regions that occur free will be
455
455
/// visited by `fld_r`.
456
- pub struct RegionFolder < ' a , I : Interner > {
456
+ pub struct RegionFolder < I , F > {
457
457
cx : I ,
458
458
459
459
/// Stores the index of a binder *just outside* the stuff we have
@@ -464,20 +464,21 @@ pub struct RegionFolder<'a, I: Interner> {
464
464
/// Callback invokes for each free region. The `DebruijnIndex`
465
465
/// points to the binder *just outside* the ones we have passed
466
466
/// through.
467
- fold_region_fn : & ' a mut ( dyn FnMut ( I :: Region , ty :: DebruijnIndex ) -> I :: Region + ' a ) ,
467
+ fold_region_fn : F ,
468
468
}
469
469
470
- impl < ' a , I : Interner > RegionFolder < ' a , I > {
470
+ impl < I , F > RegionFolder < I , F > {
471
471
#[ inline]
472
- pub fn new (
473
- cx : I ,
474
- fold_region_fn : & ' a mut dyn FnMut ( I :: Region , ty:: DebruijnIndex ) -> I :: Region ,
475
- ) -> RegionFolder < ' a , I > {
472
+ pub fn new ( cx : I , fold_region_fn : F ) -> RegionFolder < I , F > {
476
473
RegionFolder { cx, current_index : ty:: INNERMOST , fold_region_fn }
477
474
}
478
475
}
479
476
480
- impl < ' a , I : Interner > TypeFolder < I > for RegionFolder < ' a , I > {
477
+ impl < I , F > TypeFolder < I > for RegionFolder < I , F >
478
+ where
479
+ I : Interner ,
480
+ F : FnMut ( I :: Region , ty:: DebruijnIndex ) -> I :: Region ,
481
+ {
481
482
fn cx ( & self ) -> I {
482
483
self . cx
483
484
}
@@ -502,4 +503,34 @@ impl<'a, I: Interner> TypeFolder<I> for RegionFolder<'a, I> {
502
503
}
503
504
}
504
505
}
506
+
507
+ fn fold_ty ( & mut self , t : I :: Ty ) -> I :: Ty {
508
+ if t. has_type_flags (
509
+ TypeFlags :: HAS_FREE_REGIONS | TypeFlags :: HAS_RE_BOUND | TypeFlags :: HAS_RE_ERASED ,
510
+ ) {
511
+ t. super_fold_with ( self )
512
+ } else {
513
+ t
514
+ }
515
+ }
516
+
517
+ fn fold_const ( & mut self , ct : I :: Const ) -> I :: Const {
518
+ if ct. has_type_flags (
519
+ TypeFlags :: HAS_FREE_REGIONS | TypeFlags :: HAS_RE_BOUND | TypeFlags :: HAS_RE_ERASED ,
520
+ ) {
521
+ ct. super_fold_with ( self )
522
+ } else {
523
+ ct
524
+ }
525
+ }
526
+
527
+ fn fold_predicate ( & mut self , p : I :: Predicate ) -> I :: Predicate {
528
+ if p. has_type_flags (
529
+ TypeFlags :: HAS_FREE_REGIONS | TypeFlags :: HAS_RE_BOUND | TypeFlags :: HAS_RE_ERASED ,
530
+ ) {
531
+ p. super_fold_with ( self )
532
+ } else {
533
+ p
534
+ }
535
+ }
505
536
}
0 commit comments