@@ -2177,61 +2177,47 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
21772177        define_scoped_cx ! ( self ) ; 
21782178
21792179        let  mut  region_index = self . region_index ; 
2180+         let  mut  next_name = |this :  & Self | loop  { 
2181+             let  name = name_by_region_index ( region_index) ; 
2182+             region_index += 1 ; 
2183+             if  !this. used_region_names . contains ( & name)  { 
2184+                 break  name; 
2185+             } 
2186+         } ; 
2187+ 
21802188        // If we want to print verbosely, then print *all* binders, even if they 
21812189        // aren't named. Eventually, we might just want this as the default, but 
21822190        // this is not *quite* right and changes the ordering of some output 
21832191        // anyways. 
21842192        let  ( new_value,  map)  = if  self . tcx ( ) . sess . verbose ( )  { 
21852193            // anon index + 1 (BrEnv takes 0) -> name 
2186-             let  mut  region_map:  BTreeMap < u32 ,   Symbol >  = BTreeMap :: default ( ) ; 
2194+             let  mut  region_map:  FxHashMap < _ ,   _ >  = Default :: default ( ) ; 
21872195            let  bound_vars = value. bound_vars ( ) ; 
21882196            for  var in  bound_vars { 
2197+                 let  ty:: BoundVariableKind :: Region ( var)  = var else  {  continue  } ; 
21892198                match  var { 
2190-                     ty:: BoundVariableKind :: Region ( ty:: BrNamed ( _ ,  name ) )  => { 
2199+                     ty:: BrAnon ( _ )  |  ty:: BrEnv  => { 
21912200                        start_or_continue ( & mut  self ,  "for<" ,  ", " ) ; 
2201+                         let  name = next_name ( & self ) ; 
21922202                        do_continue ( & mut  self ,  name) ; 
2203+                         region_map. insert ( var,  ty:: BrNamed ( CRATE_DEF_ID . to_def_id ( ) ,  name) ) ; 
21932204                    } 
2194-                     ty:: BoundVariableKind :: Region ( ty :: BrAnon ( i ) )  => { 
2205+                     ty:: BrNamed ( def_id ,  kw :: UnderscoreLifetime )  => { 
21952206                        start_or_continue ( & mut  self ,  "for<" ,  ", " ) ; 
2196-                         let  name = loop  { 
2197-                             let  name = name_by_region_index ( region_index) ; 
2198-                             region_index += 1 ; 
2199-                             if  !self . used_region_names . contains ( & name)  { 
2200-                                 break  name; 
2201-                             } 
2202-                         } ; 
2207+                         let  name = next_name ( & self ) ; 
22032208                        do_continue ( & mut  self ,  name) ; 
2204-                         region_map. insert ( i +  1 ,  name) ; 
2209+                         region_map. insert ( var ,  ty :: BrNamed ( def_id ,  name) ) ; 
22052210                    } 
2206-                     ty:: BoundVariableKind :: Region ( ty :: BrEnv )  => { 
2211+                     ty:: BrNamed ( _ ,  name )  => { 
22072212                        start_or_continue ( & mut  self ,  "for<" ,  ", " ) ; 
2208-                         let  name = loop  { 
2209-                             let  name = name_by_region_index ( region_index) ; 
2210-                             region_index += 1 ; 
2211-                             if  !self . used_region_names . contains ( & name)  { 
2212-                                 break  name; 
2213-                             } 
2214-                         } ; 
22152213                        do_continue ( & mut  self ,  name) ; 
2216-                         region_map. insert ( 0 ,  name) ; 
22172214                    } 
2218-                     _ => continue , 
22192215                } 
22202216            } 
22212217            start_or_continue ( & mut  self ,  "" ,  "> " ) ; 
22222218
22232219            self . tcx . replace_late_bound_regions ( value. clone ( ) ,  |br| { 
2224-                 let  kind = match  br. kind  { 
2225-                     ty:: BrNamed ( _,  _)  => br. kind , 
2226-                     ty:: BrAnon ( i)  => { 
2227-                         let  name = region_map[ & ( i + 1 ) ] ; 
2228-                         ty:: BrNamed ( CRATE_DEF_ID . to_def_id ( ) ,  name) 
2229-                     } 
2230-                     ty:: BrEnv  => { 
2231-                         let  name = region_map[ & 0 ] ; 
2232-                         ty:: BrNamed ( CRATE_DEF_ID . to_def_id ( ) ,  name) 
2233-                     } 
2234-                 } ; 
2220+                 let  kind = region_map[ & br. kind ] ; 
22352221                self . tcx . mk_region ( ty:: ReLateBound ( 
22362222                    ty:: INNERMOST , 
22372223                    ty:: BoundRegion  {  var :  br. var ,  kind } , 
@@ -2242,21 +2228,20 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
22422228            let  mut  name = |br :  ty:: BoundRegion | { 
22432229                start_or_continue ( & mut  self ,  "for<" ,  ", " ) ; 
22442230                let  kind = match  br. kind  { 
2245-                     ty:: BrNamed ( _,  name)  => { 
2246-                         do_continue ( & mut  self ,  name) ; 
2247-                         br. kind 
2248-                     } 
22492231                    ty:: BrAnon ( _)  | ty:: BrEnv  => { 
2250-                         let  name = loop  { 
2251-                             let  name = name_by_region_index ( region_index) ; 
2252-                             region_index += 1 ; 
2253-                             if  !self . used_region_names . contains ( & name)  { 
2254-                                 break  name; 
2255-                             } 
2256-                         } ; 
2232+                         let  name = next_name ( & self ) ; 
22572233                        do_continue ( & mut  self ,  name) ; 
22582234                        ty:: BrNamed ( CRATE_DEF_ID . to_def_id ( ) ,  name) 
22592235                    } 
2236+                     ty:: BrNamed ( def_id,  kw:: UnderscoreLifetime )  => { 
2237+                         let  name = next_name ( & self ) ; 
2238+                         do_continue ( & mut  self ,  name) ; 
2239+                         ty:: BrNamed ( def_id,  name) 
2240+                     } 
2241+                     ty:: BrNamed ( _,  name)  => { 
2242+                         do_continue ( & mut  self ,  name) ; 
2243+                         br. kind 
2244+                     } 
22602245                } ; 
22612246                tcx. mk_region ( ty:: ReLateBound ( ty:: INNERMOST ,  ty:: BoundRegion  {  var :  br. var ,  kind } ) ) 
22622247            } ; 
0 commit comments