9
9
// except according to those terms.
10
10
11
11
use super :: universal_regions:: UniversalRegions ;
12
+ use borrow_check:: nll:: region_infer:: values:: ToElementIndex ;
12
13
use rustc:: hir:: def_id:: DefId ;
13
14
use rustc:: infer:: InferCtxt ;
14
15
use rustc:: infer:: NLLRegionVariableOrigin ;
@@ -1007,7 +1008,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1007
1008
longer_fr, shorter_fr,
1008
1009
) ;
1009
1010
1010
- let blame_span = self . blame_span ( longer_fr, shorter_fr) ;
1011
+ let blame_index = self . blame_constraint ( longer_fr, shorter_fr) ;
1012
+ let blame_span = self . constraints [ blame_index] . span ;
1011
1013
1012
1014
if let Some ( propagated_outlives_requirements) = propagated_outlives_requirements {
1013
1015
// Shrink `fr` until we find a non-local region (if we do).
@@ -1095,7 +1097,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1095
1097
1096
1098
/// Tries to finds a good span to blame for the fact that `fr1`
1097
1099
/// contains `fr2`.
1098
- fn blame_span ( & self , fr1 : RegionVid , fr2 : RegionVid ) -> Span {
1100
+ fn blame_constraint ( & self , fr1 : RegionVid , elem : impl ToElementIndex ) -> ConstraintIndex {
1099
1101
// Find everything that influenced final value of `fr`.
1100
1102
let influenced_fr1 = self . dependencies ( fr1) ;
1101
1103
@@ -1108,23 +1110,23 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1108
1110
// of dependencies, which doesn't account for the locations of
1109
1111
// contraints at all. But it will do for now.
1110
1112
let relevant_constraint = self . constraints
1111
- . iter ( )
1112
- . filter_map ( |constraint| {
1113
- if constraint. sub != fr2 {
1114
- None
1115
- } else {
1116
- influenced_fr1[ constraint. sup ]
1117
- . map ( |distance| ( distance, constraint . span ) )
1118
- }
1119
- } )
1120
- . min ( ) // constraining fr1 with fewer hops *ought* to be more obvious
1121
- . map ( |( _dist, span ) | span ) ;
1113
+ . iter_enumerated ( )
1114
+ . filter_map ( |( i , constraint) | {
1115
+ if self . liveness_constraints . contains ( constraint. sub , elem ) {
1116
+ None
1117
+ } else {
1118
+ influenced_fr1[ constraint. sup ]
1119
+ . map ( |distance| ( distance, i ) )
1120
+ }
1121
+ } )
1122
+ . min ( ) // constraining fr1 with fewer hops *ought* to be more obvious
1123
+ . map ( |( _dist, i ) | i ) ;
1122
1124
1123
1125
relevant_constraint. unwrap_or_else ( || {
1124
1126
bug ! (
1125
1127
"could not find any constraint to blame for {:?}: {:?}" ,
1126
1128
fr1,
1127
- fr2
1129
+ elem ,
1128
1130
) ;
1129
1131
} )
1130
1132
}
0 commit comments