@@ -101,7 +101,7 @@ struct RegionDefinition<'tcx> {
101
101
/// NB: The variants in `Cause` are intentionally ordered. Lower
102
102
/// values are preferred when it comes to error messages. Do not
103
103
/// reorder willy nilly.
104
- #[ derive( Clone , Debug , PartialOrd , Ord , PartialEq , Eq ) ]
104
+ #[ derive( Copy , Clone , Debug , PartialOrd , Ord , PartialEq , Eq ) ]
105
105
pub ( crate ) enum Cause {
106
106
/// point inserted because Local was live at the given Location
107
107
LiveVar ( Local , Location ) ,
@@ -115,23 +115,6 @@ pub(crate) enum Cause {
115
115
116
116
/// part of the initial set of values for a universally quantified region
117
117
UniversalRegion ( RegionVid ) ,
118
-
119
- /// Element E was added to R because there was some
120
- /// outlives obligation `R: R1 @ P` and `R1` contained `E`.
121
- Outlives {
122
- /// the reason that R1 had E
123
- original_cause : Rc < Cause > ,
124
-
125
- /// the point P from the relation
126
- constraint_location : Location ,
127
-
128
- /// The span indicating why we added the outlives constraint.
129
- constraint_span : Span ,
130
- } ,
131
- }
132
-
133
- pub ( crate ) struct RegionCausalInfo {
134
- inferred_values : RegionValues ,
135
118
}
136
119
137
120
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
@@ -477,21 +460,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
477
460
}
478
461
}
479
462
480
- /// Re-execute the region inference, this time tracking causal information.
481
- /// This is significantly slower, so it is done only when an error is being reported.
482
- pub ( super ) fn compute_causal_info ( & self , mir : & Mir < ' tcx > ) -> RegionCausalInfo {
483
- let dfs_storage = & mut self . new_dfs_storage ( ) ;
484
- let inferred_values = self . compute_region_values ( mir, dfs_storage, TrackCauses ( true ) ) ;
485
- RegionCausalInfo { inferred_values }
486
- }
487
-
488
463
/// Propagate the region constraints: this will grow the values
489
464
/// for each region variable until all the constraints are
490
465
/// satisfied. Note that some values may grow **too** large to be
491
466
/// feasible, but we check this later.
492
467
fn propagate_constraints ( & mut self , mir : & Mir < ' tcx > , dfs_storage : & mut dfs:: DfsStorage ) {
493
468
self . dependency_map = Some ( self . build_dependency_map ( ) ) ;
494
- let inferred_values = self . compute_region_values ( mir, dfs_storage, TrackCauses ( false ) ) ;
469
+ let inferred_values = self . compute_region_values ( mir, dfs_storage) ;
495
470
self . inferred_values = Some ( inferred_values) ;
496
471
}
497
472
@@ -500,7 +475,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
500
475
& self ,
501
476
mir : & Mir < ' tcx > ,
502
477
dfs_storage : & mut dfs:: DfsStorage ,
503
- track_causes : TrackCauses ,
504
478
) -> RegionValues {
505
479
debug ! ( "compute_region_values()" ) ;
506
480
debug ! ( "compute_region_values: constraints={:#?}" , {
@@ -511,7 +485,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
511
485
512
486
// The initial values for each region are derived from the liveness
513
487
// constraints we have accumulated.
514
- let mut inferred_values = self . liveness_constraints . duplicate ( track_causes ) ;
488
+ let mut inferred_values = self . liveness_constraints . duplicate ( TrackCauses ( false ) ) ;
515
489
516
490
let dependency_map = self . dependency_map . as_ref ( ) . unwrap ( ) ;
517
491
@@ -1095,6 +1069,17 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1095
1069
diag. emit ( ) ;
1096
1070
}
1097
1071
1072
+ crate fn why_region_contains_point ( & self , fr1 : RegionVid , elem : Location ) -> Option < Cause > {
1073
+ // Find some constraint `X: Y` where:
1074
+ // - `fr1: X` transitively
1075
+ // - and `Y` is live at `elem`
1076
+ let index = self . blame_constraint ( fr1, elem) ;
1077
+ let region_sub = self . constraints [ index] . sub ;
1078
+
1079
+ // then return why `Y` was live at `elem`
1080
+ self . liveness_constraints . cause ( region_sub, elem)
1081
+ }
1082
+
1098
1083
/// Tries to finds a good span to blame for the fact that `fr1`
1099
1084
/// contains `fr2`.
1100
1085
fn blame_constraint ( & self , fr1 : RegionVid , elem : impl ToElementIndex ) -> ConstraintIndex {
@@ -1112,7 +1097,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1112
1097
let relevant_constraint = self . constraints
1113
1098
. iter_enumerated ( )
1114
1099
. filter_map ( |( i, constraint) | {
1115
- if self . liveness_constraints . contains ( constraint. sub , elem) {
1100
+ if ! self . liveness_constraints . contains ( constraint. sub , elem) {
1116
1101
None
1117
1102
} else {
1118
1103
influenced_fr1[ constraint. sup ]
@@ -1163,16 +1148,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1163
1148
}
1164
1149
}
1165
1150
1166
- impl RegionCausalInfo {
1167
- /// Returns the *reason* that the region `r` contains the given point.
1168
- pub ( super ) fn why_region_contains_point < R > ( & self , r : R , p : Location ) -> Option < Rc < Cause > >
1169
- where
1170
- R : ToRegionVid ,
1171
- {
1172
- self . inferred_values . cause ( r. to_region_vid ( ) , p)
1173
- }
1174
- }
1175
-
1176
1151
impl < ' tcx > RegionDefinition < ' tcx > {
1177
1152
fn new ( origin : RegionVariableOrigin ) -> Self {
1178
1153
// Create a new region definition. Note that, for free
@@ -1316,31 +1291,3 @@ impl<'gcx, 'tcx> ClosureRegionRequirementsExt<'gcx, 'tcx> for ClosureRegionRequi
1316
1291
} )
1317
1292
}
1318
1293
}
1319
-
1320
- trait CauseExt {
1321
- fn outlives ( & self , constraint_location : Location , constraint_span : Span ) -> Cause ;
1322
- }
1323
-
1324
- impl CauseExt for Rc < Cause > {
1325
- /// Creates a derived cause due to an outlives constraint.
1326
- fn outlives ( & self , constraint_location : Location , constraint_span : Span ) -> Cause {
1327
- Cause :: Outlives {
1328
- original_cause : self . clone ( ) ,
1329
- constraint_location,
1330
- constraint_span,
1331
- }
1332
- }
1333
- }
1334
-
1335
- impl Cause {
1336
- pub ( crate ) fn root_cause ( & self ) -> & Cause {
1337
- match self {
1338
- Cause :: LiveVar ( ..)
1339
- | Cause :: DropVar ( ..)
1340
- | Cause :: LiveOther ( ..)
1341
- | Cause :: UniversalRegion ( ..) => self ,
1342
-
1343
- Cause :: Outlives { original_cause, .. } => original_cause. root_cause ( ) ,
1344
- }
1345
- }
1346
- }
0 commit comments