@@ -2057,8 +2057,8 @@ struct RegionFolder<'a, 'tcx> {
20572057 region_map : BTreeMap < ty:: BoundRegion , ty:: Region < ' tcx > > ,
20582058 name : & ' a mut (
20592059 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
20622062 ty:: BoundRegion ,
20632063 ) -> ty:: Region < ' tcx >
20642064 + ' a
@@ -2246,15 +2246,21 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
22462246 } )
22472247 } else {
22482248 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 ,
22512257 br : ty:: BoundRegion | {
22522258 let ( name, kind) = match br. kind {
22532259 ty:: BrAnon ( _) | ty:: BrEnv => {
22542260 let name = next_name ( & self ) ;
22552261
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 {
22582264 let kind = ty:: BrNamed ( CRATE_DEF_ID . to_def_id ( ) , name) ;
22592265 return tcx. mk_region ( ty:: ReLateBound (
22602266 ty:: INNERMOST ,
@@ -2268,8 +2274,8 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
22682274 ty:: BrNamed ( def_id, kw:: UnderscoreLifetime ) => {
22692275 let name = next_name ( & self ) ;
22702276
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 {
22732279 let kind = ty:: BrNamed ( def_id, name) ;
22742280 return tcx. mk_region ( ty:: ReLateBound (
22752281 ty:: INNERMOST ,
@@ -2281,8 +2287,8 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
22812287 ( name, ty:: BrNamed ( def_id, name) )
22822288 }
22832289 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 {
22862292 let kind = br. kind ;
22872293 return tcx. mk_region ( ty:: ReLateBound (
22882294 ty:: INNERMOST ,
0 commit comments