@@ -2057,8 +2057,8 @@ struct RegionFolder<'a, 'tcx> {
2057
2057
region_map : BTreeMap < ty:: BoundRegion , ty:: Region < ' tcx > > ,
2058
2058
name : & ' a mut (
2059
2059
dyn FnMut (
2060
- Option < ty:: DebruijnIndex > ,
2061
- ty:: DebruijnIndex ,
2060
+ Option < ty:: DebruijnIndex > , // Debruijn index of the folded late-bound region
2061
+ ty:: DebruijnIndex , // Index corresponding to binder level
2062
2062
ty:: BoundRegion ,
2063
2063
) -> ty:: Region < ' tcx >
2064
2064
+ ' a
@@ -2246,15 +2246,21 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
2246
2246
} )
2247
2247
} else {
2248
2248
let tcx = self . tcx ;
2249
- let mut name = |db : Option < ty:: DebruijnIndex > ,
2250
- binder_level : ty:: DebruijnIndex ,
2249
+
2250
+ // Closure used in `RegionFolder` to create names for anonymous late-bound
2251
+ // regions. We use two `DebruijnIndex`es (one for the currently folded
2252
+ // late-bound region and the other for the binder level) to determine
2253
+ // whether a name has already been created for the currently folded region,
2254
+ // see issue #102392.
2255
+ let mut name = |lifetime_idx : Option < ty:: DebruijnIndex > ,
2256
+ binder_level_idx : ty:: DebruijnIndex ,
2251
2257
br : ty:: BoundRegion | {
2252
2258
let ( name, kind) = match br. kind {
2253
2259
ty:: BrAnon ( _) | ty:: BrEnv => {
2254
2260
let name = next_name ( & self ) ;
2255
2261
2256
- if let Some ( db ) = db {
2257
- if db > binder_level {
2262
+ if let Some ( lt_idx ) = lifetime_idx {
2263
+ if lt_idx > binder_level_idx {
2258
2264
let kind = ty:: BrNamed ( CRATE_DEF_ID . to_def_id ( ) , name) ;
2259
2265
return tcx. mk_region ( ty:: ReLateBound (
2260
2266
ty:: INNERMOST ,
@@ -2268,8 +2274,8 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
2268
2274
ty:: BrNamed ( def_id, kw:: UnderscoreLifetime ) => {
2269
2275
let name = next_name ( & self ) ;
2270
2276
2271
- if let Some ( db ) = db {
2272
- if db > binder_level {
2277
+ if let Some ( lt_idx ) = lifetime_idx {
2278
+ if lt_idx > binder_level_idx {
2273
2279
let kind = ty:: BrNamed ( def_id, name) ;
2274
2280
return tcx. mk_region ( ty:: ReLateBound (
2275
2281
ty:: INNERMOST ,
@@ -2281,8 +2287,8 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
2281
2287
( name, ty:: BrNamed ( def_id, name) )
2282
2288
}
2283
2289
ty:: BrNamed ( _, name) => {
2284
- if let Some ( db ) = db {
2285
- if db > binder_level {
2290
+ if let Some ( lt_idx ) = lifetime_idx {
2291
+ if lt_idx > binder_level_idx {
2286
2292
let kind = br. kind ;
2287
2293
return tcx. mk_region ( ty:: ReLateBound (
2288
2294
ty:: INNERMOST ,
0 commit comments