@@ -2177,61 +2177,47 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
2177
2177
define_scoped_cx ! ( self ) ;
2178
2178
2179
2179
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
+
2180
2188
// If we want to print verbosely, then print *all* binders, even if they
2181
2189
// aren't named. Eventually, we might just want this as the default, but
2182
2190
// this is not *quite* right and changes the ordering of some output
2183
2191
// anyways.
2184
2192
let ( new_value, map) = if self . tcx ( ) . sess . verbose ( ) {
2185
2193
// 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 ( ) ;
2187
2195
let bound_vars = value. bound_vars ( ) ;
2188
2196
for var in bound_vars {
2197
+ let ty:: BoundVariableKind :: Region ( var) = var else { continue } ;
2189
2198
match var {
2190
- ty:: BoundVariableKind :: Region ( ty:: BrNamed ( _ , name ) ) => {
2199
+ ty:: BrAnon ( _ ) | ty:: BrEnv => {
2191
2200
start_or_continue ( & mut self , "for<" , ", " ) ;
2201
+ let name = next_name ( & self ) ;
2192
2202
do_continue ( & mut self , name) ;
2203
+ region_map. insert ( var, ty:: BrNamed ( CRATE_DEF_ID . to_def_id ( ) , name) ) ;
2193
2204
}
2194
- ty:: BoundVariableKind :: Region ( ty :: BrAnon ( i ) ) => {
2205
+ ty:: BrNamed ( def_id , kw :: UnderscoreLifetime ) => {
2195
2206
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 ) ;
2203
2208
do_continue ( & mut self , name) ;
2204
- region_map. insert ( i + 1 , name) ;
2209
+ region_map. insert ( var , ty :: BrNamed ( def_id , name) ) ;
2205
2210
}
2206
- ty:: BoundVariableKind :: Region ( ty :: BrEnv ) => {
2211
+ ty:: BrNamed ( _ , name ) => {
2207
2212
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
- } ;
2215
2213
do_continue ( & mut self , name) ;
2216
- region_map. insert ( 0 , name) ;
2217
2214
}
2218
- _ => continue ,
2219
2215
}
2220
2216
}
2221
2217
start_or_continue ( & mut self , "" , "> " ) ;
2222
2218
2223
2219
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 ] ;
2235
2221
self . tcx . mk_region ( ty:: ReLateBound (
2236
2222
ty:: INNERMOST ,
2237
2223
ty:: BoundRegion { var : br. var , kind } ,
@@ -2242,21 +2228,20 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
2242
2228
let mut name = |br : ty:: BoundRegion | {
2243
2229
start_or_continue ( & mut self , "for<" , ", " ) ;
2244
2230
let kind = match br. kind {
2245
- ty:: BrNamed ( _, name) => {
2246
- do_continue ( & mut self , name) ;
2247
- br. kind
2248
- }
2249
2231
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 ) ;
2257
2233
do_continue ( & mut self , name) ;
2258
2234
ty:: BrNamed ( CRATE_DEF_ID . to_def_id ( ) , name)
2259
2235
}
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
+ }
2260
2245
} ;
2261
2246
tcx. mk_region ( ty:: ReLateBound ( ty:: INNERMOST , ty:: BoundRegion { var : br. var , kind } ) )
2262
2247
} ;
0 commit comments