@@ -806,29 +806,31 @@ impl<'tcx> ctxt<'tcx> {
806
806
// recursing over the type itself.
807
807
bitflags ! {
808
808
flags TypeFlags : u32 {
809
- const HAS_PARAMS = 1 << 0 ,
810
- const HAS_SELF = 1 << 1 ,
811
- const HAS_TY_INFER = 1 << 2 ,
812
- const HAS_RE_INFER = 1 << 3 ,
813
- const HAS_RE_LATE_BOUND = 1 << 4 ,
814
- const HAS_REGIONS = 1 << 5 ,
815
- const HAS_TY_ERR = 1 << 6 ,
816
- const HAS_PROJECTION = 1 << 7 ,
817
- const HAS_TY_CLOSURE = 1 << 8 ,
818
- const NEEDS_SUBST = TypeFlags :: HAS_PARAMS . bits |
819
- TypeFlags :: HAS_SELF . bits |
820
- TypeFlags :: HAS_REGIONS . bits,
809
+ const HAS_PARAMS = 1 << 0 ,
810
+ const HAS_SELF = 1 << 1 ,
811
+ const HAS_TY_INFER = 1 << 2 ,
812
+ const HAS_RE_INFER = 1 << 3 ,
813
+ const HAS_RE_EARLY_BOUND = 1 << 4 ,
814
+ const HAS_FREE_REGIONS = 1 << 5 ,
815
+ const HAS_TY_ERR = 1 << 6 ,
816
+ const HAS_PROJECTION = 1 << 7 ,
817
+ const HAS_TY_CLOSURE = 1 << 8 ,
818
+ const NEEDS_SUBST = TypeFlags :: HAS_PARAMS . bits |
819
+ TypeFlags :: HAS_SELF . bits |
820
+ TypeFlags :: HAS_RE_EARLY_BOUND . bits,
821
821
822
822
// Flags representing the nominal content of a type,
823
- // computed by FlagsComputetion
823
+ // computed by FlagsComputation. If you add a new nominal
824
+ // flag, it should be added here too.
824
825
const NOMINAL_FLAGS = TypeFlags :: HAS_PARAMS . bits |
825
826
TypeFlags :: HAS_SELF . bits |
826
827
TypeFlags :: HAS_TY_INFER . bits |
827
828
TypeFlags :: HAS_RE_INFER . bits |
828
- TypeFlags :: HAS_RE_LATE_BOUND . bits |
829
- TypeFlags :: HAS_REGIONS . bits |
829
+ TypeFlags :: HAS_RE_EARLY_BOUND . bits |
830
+ TypeFlags :: HAS_FREE_REGIONS . bits |
830
831
TypeFlags :: HAS_TY_ERR . bits |
831
- TypeFlags :: HAS_PROJECTION . bits,
832
+ TypeFlags :: HAS_PROJECTION . bits |
833
+ TypeFlags :: HAS_TY_CLOSURE . bits,
832
834
833
835
// Caches for type_is_sized, type_moves_by_default
834
836
const SIZEDNESS_CACHED = 1 << 16 ,
@@ -990,8 +992,10 @@ pub fn type_has_ty_closure(ty: Ty) -> bool {
990
992
ty. flags . get ( ) . intersects ( TypeFlags :: HAS_TY_CLOSURE )
991
993
}
992
994
993
- pub fn type_has_late_bound_regions ( ty : Ty ) -> bool {
994
- ty. flags . get ( ) . intersects ( TypeFlags :: HAS_RE_LATE_BOUND )
995
+ pub fn type_has_erasable_regions ( ty : Ty ) -> bool {
996
+ ty. flags . get ( ) . intersects ( TypeFlags :: HAS_RE_EARLY_BOUND |
997
+ TypeFlags :: HAS_RE_INFER |
998
+ TypeFlags :: HAS_FREE_REGIONS )
995
999
}
996
1000
997
1001
/// An "escaping region" is a bound region whose binder is not part of `t`.
@@ -2987,7 +2991,7 @@ impl FlagComputation {
2987
2991
for projection_bound in & bounds. projection_bounds {
2988
2992
let mut proj_computation = FlagComputation :: new ( ) ;
2989
2993
proj_computation. add_projection_predicate ( & projection_bound. 0 ) ;
2990
- computation . add_bound_computation ( & proj_computation) ;
2994
+ self . add_bound_computation ( & proj_computation) ;
2991
2995
}
2992
2996
self . add_bound_computation ( & computation) ;
2993
2997
@@ -3041,14 +3045,12 @@ impl FlagComputation {
3041
3045
}
3042
3046
3043
3047
fn add_region ( & mut self , r : Region ) {
3044
- self . add_flags ( TypeFlags :: HAS_REGIONS ) ;
3045
3048
match r {
3046
3049
ty:: ReInfer ( _) => { self . add_flags ( TypeFlags :: HAS_RE_INFER ) ; }
3047
- ty:: ReLateBound ( debruijn, _) => {
3048
- self . add_flags ( TypeFlags :: HAS_RE_LATE_BOUND ) ;
3049
- self . add_depth ( debruijn. depth ) ;
3050
- }
3051
- _ => { }
3050
+ ty:: ReLateBound ( debruijn, _) => { self . add_depth ( debruijn. depth ) ; }
3051
+ ty:: ReEarlyBound ( ..) => { self . add_flags ( TypeFlags :: HAS_RE_EARLY_BOUND ) ; }
3052
+ ty:: ReStatic => { }
3053
+ _ => { self . add_flags ( TypeFlags :: HAS_FREE_REGIONS ) ; }
3052
3054
}
3053
3055
}
3054
3056
@@ -6994,7 +6996,7 @@ pub fn liberate_late_bound_regions<'tcx, T>(
6994
6996
-> T
6995
6997
where T : TypeFoldable < ' tcx > + Repr < ' tcx >
6996
6998
{
6997
- replace_late_bound_regions (
6999
+ ty_fold :: replace_late_bound_regions (
6998
7000
tcx, value,
6999
7001
|br| ty:: ReFree ( ty:: FreeRegion { scope : all_outlive_scope, bound_region : br} ) ) . 0
7000
7002
}
@@ -7005,7 +7007,7 @@ pub fn count_late_bound_regions<'tcx, T>(
7005
7007
-> usize
7006
7008
where T : TypeFoldable < ' tcx > + Repr < ' tcx >
7007
7009
{
7008
- let ( _, skol_map) = replace_late_bound_regions ( tcx, value, |_| ty:: ReStatic ) ;
7010
+ let ( _, skol_map) = ty_fold :: replace_late_bound_regions ( tcx, value, |_| ty:: ReStatic ) ;
7009
7011
skol_map. len ( )
7010
7012
}
7011
7013
@@ -7063,7 +7065,7 @@ pub fn erase_late_bound_regions<'tcx, T>(
7063
7065
-> T
7064
7066
where T : TypeFoldable < ' tcx > + Repr < ' tcx >
7065
7067
{
7066
- replace_late_bound_regions ( tcx, value, |_| ty:: ReStatic ) . 0
7068
+ ty_fold :: replace_late_bound_regions ( tcx, value, |_| ty:: ReStatic ) . 0
7067
7069
}
7068
7070
7069
7071
/// Rewrite any late-bound regions so that they are anonymous. Region numbers are
@@ -7081,53 +7083,12 @@ pub fn anonymize_late_bound_regions<'tcx, T>(
7081
7083
where T : TypeFoldable < ' tcx > + Repr < ' tcx > ,
7082
7084
{
7083
7085
let mut counter = 0 ;
7084
- ty:: Binder ( replace_late_bound_regions ( tcx, sig, |_| {
7086
+ ty:: Binder ( ty_fold :: replace_late_bound_regions ( tcx, sig, |_| {
7085
7087
counter += 1 ;
7086
7088
ReLateBound ( ty:: DebruijnIndex :: new ( 1 ) , BrAnon ( counter) )
7087
7089
} ) . 0 )
7088
7090
}
7089
7091
7090
- /// Replaces the late-bound-regions in `value` that are bound by `value`.
7091
- pub fn replace_late_bound_regions < ' tcx , T , F > (
7092
- tcx : & ty:: ctxt < ' tcx > ,
7093
- binder : & Binder < T > ,
7094
- mut mapf : F )
7095
- -> ( T , FnvHashMap < ty:: BoundRegion , ty:: Region > )
7096
- where T : TypeFoldable < ' tcx > + Repr < ' tcx > ,
7097
- F : FnMut ( BoundRegion ) -> ty:: Region ,
7098
- {
7099
- debug ! ( "replace_late_bound_regions({})" , binder. repr( tcx) ) ;
7100
-
7101
- let mut map = FnvHashMap ( ) ;
7102
-
7103
- // Note: fold the field `0`, not the binder, so that late-bound
7104
- // regions bound by `binder` are considered free.
7105
- let value = ty_fold:: fold_regions ( tcx, & binder. 0 , |region, current_depth| {
7106
- debug ! ( "region={}" , region. repr( tcx) ) ;
7107
- match region {
7108
- ty:: ReLateBound ( debruijn, br) if debruijn. depth == current_depth => {
7109
- let region = * map. entry ( br) . or_insert_with ( || mapf ( br) ) ;
7110
-
7111
- if let ty:: ReLateBound ( debruijn1, br) = region {
7112
- // If the callback returns a late-bound region,
7113
- // that region should always use depth 1. Then we
7114
- // adjust it to the correct depth.
7115
- assert_eq ! ( debruijn1. depth, 1 ) ;
7116
- ty:: ReLateBound ( debruijn, br)
7117
- } else {
7118
- region
7119
- }
7120
- }
7121
- _ => {
7122
- region
7123
- }
7124
- }
7125
- } ) ;
7126
-
7127
- debug ! ( "resulting map: {:?} value: {:?}" , map, value. repr( tcx) ) ;
7128
- ( value, map)
7129
- }
7130
-
7131
7092
impl DebruijnIndex {
7132
7093
pub fn new ( depth : u32 ) -> DebruijnIndex {
7133
7094
assert ! ( depth > 0 ) ;
0 commit comments