@@ -1713,6 +1713,16 @@ impl Region {
17131713 _ => false ,
17141714 }
17151715 }
1716+
1717+ /// Returns the depth of `self` from the (1-based) binding level `depth`
1718+ pub fn from_depth ( & self , depth : u32 ) -> Region {
1719+ match * self {
1720+ ty:: ReLateBound ( debruijn, r) => ty:: ReLateBound ( DebruijnIndex {
1721+ depth : debruijn. depth - ( depth - 1 )
1722+ } , r) ,
1723+ r => r
1724+ }
1725+ }
17161726}
17171727
17181728#[ derive( Clone , PartialEq , PartialOrd , Eq , Ord , Hash ,
@@ -6783,60 +6793,6 @@ pub enum ExplicitSelfCategory {
67836793 ByBoxExplicitSelfCategory ,
67846794}
67856795
6786- impl < ' tcx > TyS < ' tcx > {
6787- /// Pushes all the lifetimes in the given type onto the given list. A
6788- /// "lifetime in a type" is a lifetime specified by a reference or a lifetime
6789- /// in a list of type substitutions. This does *not* traverse into nominal
6790- /// types, nor does it resolve fictitious types.
6791- pub fn accumulate_lifetimes_in_type ( & self , accumulator : & mut Vec < ty:: Region > ) {
6792- for ty in self . walk ( ) {
6793- match ty. sty {
6794- TyRef ( region, _) => {
6795- accumulator. push ( * region)
6796- }
6797- TyTrait ( ref t) => {
6798- accumulator. push_all ( t. principal . 0 . substs . regions ( ) . as_slice ( ) ) ;
6799- }
6800- TyEnum ( _, substs) |
6801- TyStruct ( _, substs) => {
6802- accum_substs ( accumulator, substs) ;
6803- }
6804- TyClosure ( _, substs) => {
6805- accum_substs ( accumulator, substs) ;
6806- }
6807- TyBool |
6808- TyChar |
6809- TyInt ( _) |
6810- TyUint ( _) |
6811- TyFloat ( _) |
6812- TyBox ( _) |
6813- TyStr |
6814- TyArray ( _, _) |
6815- TySlice ( _) |
6816- TyRawPtr ( _) |
6817- TyBareFn ( ..) |
6818- TyTuple ( _) |
6819- TyProjection ( _) |
6820- TyParam ( _) |
6821- TyInfer ( _) |
6822- TyError => {
6823- }
6824- }
6825- }
6826-
6827- fn accum_substs ( accumulator : & mut Vec < Region > , substs : & Substs ) {
6828- match substs. regions {
6829- subst:: ErasedRegions => { }
6830- subst:: NonerasedRegions ( ref regions) => {
6831- for region in regions {
6832- accumulator. push ( * region)
6833- }
6834- }
6835- }
6836- }
6837- }
6838- }
6839-
68406796/// A free variable referred to in a function.
68416797#[ derive( Copy , Clone , RustcEncodable , RustcDecodable ) ]
68426798pub struct Freevar {
@@ -6897,27 +6853,15 @@ impl<'tcx> ctxt<'tcx> {
68976853 |br| ty:: ReFree ( ty:: FreeRegion { scope : all_outlive_scope, bound_region : br} ) ) . 0
68986854 }
68996855
6900- pub fn count_late_bound_regions < T > ( & self , value : & Binder < T > ) -> usize
6901- where T : TypeFoldable < ' tcx >
6902- {
6903- let ( _, skol_map) = ty_fold:: replace_late_bound_regions ( self , value, |_| ty:: ReStatic ) ;
6904- skol_map. len ( )
6905- }
6906-
6907- pub fn binds_late_bound_regions < T > ( & self , value : & Binder < T > ) -> bool
6908- where T : TypeFoldable < ' tcx >
6909- {
6910- self . count_late_bound_regions ( value) > 0
6911- }
6912-
69136856 /// Flattens two binding levels into one. So `for<'a> for<'b> Foo`
69146857 /// becomes `for<'a,'b> Foo`.
69156858 pub fn flatten_late_bound_regions < T > ( & self , bound2_value : & Binder < Binder < T > > )
69166859 -> Binder < T >
69176860 where T : TypeFoldable < ' tcx >
69186861 {
69196862 let bound0_value = bound2_value. skip_binder ( ) . skip_binder ( ) ;
6920- let value = ty_fold:: fold_regions ( self , bound0_value, |region, current_depth| {
6863+ let value = ty_fold:: fold_regions ( self , bound0_value, & mut false ,
6864+ |region, current_depth| {
69216865 match region {
69226866 ty:: ReLateBound ( debruijn, br) if debruijn. depth >= current_depth => {
69236867 // should be true if no escaping regions from bound2_value
@@ -6933,9 +6877,9 @@ impl<'tcx> ctxt<'tcx> {
69336877 }
69346878
69356879 pub fn no_late_bound_regions < T > ( & self , value : & Binder < T > ) -> Option < T >
6936- where T : TypeFoldable < ' tcx >
6880+ where T : TypeFoldable < ' tcx > + RegionEscape
69376881 {
6938- if self . binds_late_bound_regions ( value ) {
6882+ if value . 0 . has_escaping_regions ( ) {
69396883 None
69406884 } else {
69416885 Some ( value. 0 . clone ( ) )
@@ -7095,6 +7039,19 @@ impl<'tcx> RegionEscape for Substs<'tcx> {
70957039 }
70967040}
70977041
7042+ impl < T : RegionEscape > RegionEscape for Vec < T > {
7043+ fn has_regions_escaping_depth ( & self , depth : u32 ) -> bool {
7044+ self . iter ( ) . any ( |t| t. has_regions_escaping_depth ( depth) )
7045+ }
7046+ }
7047+
7048+ impl < ' tcx > RegionEscape for FnSig < ' tcx > {
7049+ fn has_regions_escaping_depth ( & self , depth : u32 ) -> bool {
7050+ self . inputs . has_regions_escaping_depth ( depth) ||
7051+ self . output . has_regions_escaping_depth ( depth)
7052+ }
7053+ }
7054+
70987055impl < ' tcx , T : RegionEscape > RegionEscape for VecPerParamSpace < T > {
70997056 fn has_regions_escaping_depth ( & self , depth : u32 ) -> bool {
71007057 self . iter_enumerated ( ) . any ( |( space, _, t) | {
@@ -7167,6 +7124,15 @@ impl<'tcx,T:RegionEscape> RegionEscape for Binder<T> {
71677124 }
71687125}
71697126
7127+ impl < ' tcx > RegionEscape for FnOutput < ' tcx > {
7128+ fn has_regions_escaping_depth ( & self , depth : u32 ) -> bool {
7129+ match * self {
7130+ FnConverging ( t) => t. has_regions_escaping_depth ( depth) ,
7131+ FnDiverging => false
7132+ }
7133+ }
7134+ }
7135+
71707136impl < ' tcx > RegionEscape for EquatePredicate < ' tcx > {
71717137 fn has_regions_escaping_depth ( & self , depth : u32 ) -> bool {
71727138 self . 0 . has_regions_escaping_depth ( depth) || self . 1 . has_regions_escaping_depth ( depth)
0 commit comments