@@ -215,8 +215,11 @@ impl RegionValues {
215
215
// FIXME. We could optimize this by improving
216
216
// `BitMatrix::merge` so it does not always merge an entire
217
217
// row.
218
- debug ! ( "add_universal_regions_outlived_by(from_region={:?}, to_region={:?})" ,
219
- from_region, to_region) ;
218
+ debug ! (
219
+ "add_universal_regions_outlived_by(from_region={:?}, to_region={:?})" ,
220
+ from_region,
221
+ to_region
222
+ ) ;
220
223
let mut changed = false ;
221
224
for elem in self . elements . all_universal_region_indices ( ) {
222
225
if self . contains ( from_region, elem) {
@@ -269,24 +272,70 @@ impl RegionValues {
269
272
let mut result = String :: new ( ) ;
270
273
result. push_str ( "{" ) ;
271
274
272
- for ( index, element) in self . elements_contained_in ( r) . enumerate ( ) {
273
- if index > 0 {
274
- result. push_str ( ", " ) ;
275
- }
275
+ // Set to Some(l1, l2) when we have observed all the locations
276
+ // from l1..=l2 (inclusive) but not yet printed them. This
277
+ // gets extended if we then see l3 where l3 is the successor
278
+ // to l2.
279
+ let mut open_location: Option < ( Location , Location ) > = None ;
280
+
281
+ let mut sep = "" ;
282
+ let mut push_sep = |s : & mut String | {
283
+ s. push_str ( sep) ;
284
+ sep = ", " ;
285
+ } ;
276
286
287
+ for element in self . elements_contained_in ( r) {
277
288
match element {
278
289
RegionElement :: Location ( l) => {
279
- result. push_str ( & format ! ( "{:?}" , l) ) ;
290
+ if let Some ( ( location1, location2) ) = open_location {
291
+ if location2. block == l. block
292
+ && location2. statement_index == l. statement_index - 1
293
+ {
294
+ open_location = Some ( ( location1, l) ) ;
295
+ continue ;
296
+ }
297
+
298
+ push_sep ( & mut result) ;
299
+ Self :: push_location_range ( & mut result, location1, location2) ;
300
+ }
301
+
302
+ open_location = Some ( ( l, l) ) ;
280
303
}
281
304
282
305
RegionElement :: UniversalRegion ( fr) => {
306
+ if let Some ( ( location1, location2) ) = open_location {
307
+ push_sep ( & mut result) ;
308
+ Self :: push_location_range ( & mut result, location1, location2) ;
309
+ open_location = None ;
310
+ }
311
+
312
+ push_sep ( & mut result) ;
283
313
result. push_str ( & format ! ( "{:?}" , fr) ) ;
284
314
}
285
315
}
286
316
}
287
317
318
+ if let Some ( ( location1, location2) ) = open_location {
319
+ push_sep ( & mut result) ;
320
+ Self :: push_location_range ( & mut result, location1, location2) ;
321
+ }
322
+
288
323
result. push_str ( "}" ) ;
289
324
290
325
result
291
326
}
327
+
328
+ fn push_location_range ( str : & mut String , location1 : Location , location2 : Location ) {
329
+ if location1 == location2 {
330
+ str. push_str ( & format ! ( "{:?}" , location1) ) ;
331
+ } else {
332
+ assert_eq ! ( location1. block, location2. block) ;
333
+ str. push_str ( & format ! (
334
+ "{:?}[{}..={}]" ,
335
+ location1. block,
336
+ location1. statement_index,
337
+ location2. statement_index
338
+ ) ) ;
339
+ }
340
+ }
292
341
}
0 commit comments