@@ -89,10 +89,12 @@ impl Region {
89
89
}
90
90
}
91
91
92
- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
92
+ #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
93
93
pub struct Constraint {
94
- /// Where did this constraint arise?
95
- span : Span ,
94
+ // NB. The ordering here is not significant for correctness, but
95
+ // it is for conenience. Before we dump the constraints in the
96
+ // debugging logs, we sort them, and we'd like the "super region"
97
+ // to be first, etc. (In particular, span should remain last.)
96
98
97
99
/// The region SUP must outlive SUB...
98
100
sup : RegionVid ,
@@ -102,6 +104,9 @@ pub struct Constraint {
102
104
103
105
/// At this location.
104
106
point : Location ,
107
+
108
+ /// Where did this constraint arise?
109
+ span : Span ,
105
110
}
106
111
107
112
impl < ' a , ' gcx , ' tcx > RegionInferenceContext < ' tcx > {
@@ -269,15 +274,23 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
269
274
let mut dfs = Dfs :: new ( mir) ;
270
275
let mut error_regions = FxHashSet ( ) ;
271
276
let mut errors = vec ! [ ] ;
277
+
278
+ debug ! ( "propagate_constraints()" ) ;
279
+ debug ! ( "propagate_constraints: constraints={:#?}" , {
280
+ let mut constraints: Vec <_> = self . constraints. iter( ) . collect( ) ;
281
+ constraints. sort( ) ;
282
+ constraints
283
+ } ) ;
284
+
272
285
while changed {
273
286
changed = false ;
274
287
for constraint in & self . constraints {
275
- debug ! ( "constraint: {:?}" , constraint) ;
288
+ debug ! ( "propagate_constraints: constraint= {:?}" , constraint) ;
276
289
let sub = & self . definitions [ constraint. sub ] . value . clone ( ) ;
277
290
let sup_def = & mut self . definitions [ constraint. sup ] ;
278
291
279
- debug ! ( " sub (before): {:?}" , sub) ;
280
- debug ! ( " sup (before): {:?}" , sup_def. value) ;
292
+ debug ! ( "propagate_constraints: sub (before): {:?}" , sub) ;
293
+ debug ! ( "propagate_constraints: sup (before): {:?}" , sup_def. value) ;
281
294
282
295
if !sup_def. constant {
283
296
// If this is not a constant, then grow the value as needed to
@@ -287,8 +300,8 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
287
300
changed = true ;
288
301
}
289
302
290
- debug ! ( " sup (after) : {:?}" , sup_def. value) ;
291
- debug ! ( " changed : {:?}" , changed) ;
303
+ debug ! ( "propagate_constraints: sup (after) : {:?}" , sup_def. value) ;
304
+ debug ! ( "propagate_constraints: changed : {:?}" , changed) ;
292
305
} else {
293
306
// If this is a constant, check whether it *would
294
307
// have* to grow in order for the constraint to be
@@ -304,7 +317,7 @@ impl<'a, 'gcx, 'tcx> RegionInferenceContext<'tcx> {
304
317
. difference ( & sup_def. value . free_regions )
305
318
. next ( )
306
319
. unwrap ( ) ;
307
- debug ! ( " new_region : {:?}" , new_region) ;
320
+ debug ! ( "propagate_constraints: new_region : {:?}" , new_region) ;
308
321
if error_regions. insert ( constraint. sup ) {
309
322
errors. push ( ( constraint. sup , constraint. span , new_region) ) ;
310
323
}
@@ -406,3 +419,16 @@ impl<'tcx> RegionDefinition<'tcx> {
406
419
}
407
420
}
408
421
}
422
+
423
+ impl fmt:: Debug for Constraint {
424
+ fn fmt ( & self , formatter : & mut fmt:: Formatter ) -> Result < ( ) , fmt:: Error > {
425
+ write ! (
426
+ formatter,
427
+ "({:?}: {:?} @ {:?}) due to {:?}" ,
428
+ self . sup,
429
+ self . sub,
430
+ self . point,
431
+ self . span
432
+ )
433
+ }
434
+ }
0 commit comments