@@ -2055,7 +2055,14 @@ struct RegionFolder<'a, 'tcx> {
2055
2055
tcx : TyCtxt < ' tcx > ,
2056
2056
current_index : ty:: DebruijnIndex ,
2057
2057
region_map : BTreeMap < ty:: BoundRegion , ty:: Region < ' tcx > > ,
2058
- name : & ' a mut ( dyn FnMut ( ty:: BoundRegion ) -> ty:: Region < ' tcx > + ' a ) ,
2058
+ name : & ' a mut (
2059
+ dyn FnMut (
2060
+ Option < ty:: DebruijnIndex > ,
2061
+ ty:: DebruijnIndex ,
2062
+ ty:: BoundRegion ,
2063
+ ) -> ty:: Region < ' tcx >
2064
+ + ' a
2065
+ ) ,
2059
2066
}
2060
2067
2061
2068
impl < ' a , ' tcx > ty:: TypeFolder < ' tcx > for RegionFolder < ' a , ' tcx > {
@@ -2086,7 +2093,9 @@ impl<'a, 'tcx> ty::TypeFolder<'tcx> for RegionFolder<'a, 'tcx> {
2086
2093
fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
2087
2094
let name = & mut self . name ;
2088
2095
let region = match * r {
2089
- ty:: ReLateBound ( _, br) => * self . region_map . entry ( br) . or_insert_with ( || name ( br) ) ,
2096
+ ty:: ReLateBound ( db, br) => {
2097
+ * self . region_map . entry ( br) . or_insert_with ( || name ( Some ( db) , self . current_index , br) )
2098
+ }
2090
2099
ty:: RePlaceholder ( ty:: PlaceholderRegion { name : kind, .. } ) => {
2091
2100
// If this is an anonymous placeholder, don't rename. Otherwise, in some
2092
2101
// async fns, we get a `for<'r> Send` bound
@@ -2095,7 +2104,10 @@ impl<'a, 'tcx> ty::TypeFolder<'tcx> for RegionFolder<'a, 'tcx> {
2095
2104
_ => {
2096
2105
// Index doesn't matter, since this is just for naming and these never get bound
2097
2106
let br = ty:: BoundRegion { var : ty:: BoundVar :: from_u32 ( 0 ) , kind } ;
2098
- * self . region_map . entry ( br) . or_insert_with ( || name ( br) )
2107
+ * self
2108
+ . region_map
2109
+ . entry ( br)
2110
+ . or_insert_with ( || name ( None , self . current_index , br) )
2099
2111
}
2100
2112
}
2101
2113
}
@@ -2234,24 +2246,57 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
2234
2246
} )
2235
2247
} else {
2236
2248
let tcx = self . tcx ;
2237
- let mut name = |br : ty:: BoundRegion | {
2238
- start_or_continue ( & mut self , "for<" , ", " ) ;
2239
- let kind = match br. kind {
2249
+ let mut name = |db : Option < ty:: DebruijnIndex > ,
2250
+ binder_level : ty:: DebruijnIndex ,
2251
+ br : ty:: BoundRegion | {
2252
+ let ( name, kind) = match br. kind {
2240
2253
ty:: BrAnon ( _) | ty:: BrEnv => {
2241
2254
let name = next_name ( & self ) ;
2242
- do_continue ( & mut self , name) ;
2243
- ty:: BrNamed ( CRATE_DEF_ID . to_def_id ( ) , name)
2255
+
2256
+ if let Some ( db) = db {
2257
+ if db > binder_level {
2258
+ let kind = ty:: BrNamed ( CRATE_DEF_ID . to_def_id ( ) , name) ;
2259
+ return tcx. mk_region ( ty:: ReLateBound (
2260
+ ty:: INNERMOST ,
2261
+ ty:: BoundRegion { var : br. var , kind } ,
2262
+ ) ) ;
2263
+ }
2264
+ }
2265
+
2266
+ ( name, ty:: BrNamed ( CRATE_DEF_ID . to_def_id ( ) , name) )
2244
2267
}
2245
2268
ty:: BrNamed ( def_id, kw:: UnderscoreLifetime ) => {
2246
2269
let name = next_name ( & self ) ;
2247
- do_continue ( & mut self , name) ;
2248
- ty:: BrNamed ( def_id, name)
2270
+
2271
+ if let Some ( db) = db {
2272
+ if db > binder_level {
2273
+ let kind = ty:: BrNamed ( def_id, name) ;
2274
+ return tcx. mk_region ( ty:: ReLateBound (
2275
+ ty:: INNERMOST ,
2276
+ ty:: BoundRegion { var : br. var , kind } ,
2277
+ ) ) ;
2278
+ }
2279
+ }
2280
+
2281
+ ( name, ty:: BrNamed ( def_id, name) )
2249
2282
}
2250
2283
ty:: BrNamed ( _, name) => {
2251
- do_continue ( & mut self , name) ;
2252
- br. kind
2284
+ if let Some ( db) = db {
2285
+ if db > binder_level {
2286
+ let kind = br. kind ;
2287
+ return tcx. mk_region ( ty:: ReLateBound (
2288
+ ty:: INNERMOST ,
2289
+ ty:: BoundRegion { var : br. var , kind } ,
2290
+ ) ) ;
2291
+ }
2292
+ }
2293
+
2294
+ ( name, br. kind )
2253
2295
}
2254
2296
} ;
2297
+
2298
+ start_or_continue ( & mut self , "for<" , ", " ) ;
2299
+ do_continue ( & mut self , name) ;
2255
2300
tcx. mk_region ( ty:: ReLateBound ( ty:: INNERMOST , ty:: BoundRegion { var : br. var , kind } ) )
2256
2301
} ;
2257
2302
let mut folder = RegionFolder {
0 commit comments