Skip to content

Commit 1fb17ab

Browse files
committed
generalize blame_span
1 parent e5f80f2 commit 1fb17ab

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/librustc_mir/borrow_check/nll/region_infer/mod.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
use super::universal_regions::UniversalRegions;
12+
use borrow_check::nll::region_infer::values::ToElementIndex;
1213
use rustc::hir::def_id::DefId;
1314
use rustc::infer::InferCtxt;
1415
use rustc::infer::NLLRegionVariableOrigin;
@@ -1007,7 +1008,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10071008
longer_fr, shorter_fr,
10081009
);
10091010

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;
10111013

10121014
if let Some(propagated_outlives_requirements) = propagated_outlives_requirements {
10131015
// Shrink `fr` until we find a non-local region (if we do).
@@ -1095,7 +1097,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10951097

10961098
/// Tries to finds a good span to blame for the fact that `fr1`
10971099
/// contains `fr2`.
1098-
fn blame_span(&self, fr1: RegionVid, fr2: RegionVid) -> Span {
1100+
fn blame_constraint(&self, fr1: RegionVid, elem: impl ToElementIndex) -> ConstraintIndex {
10991101
// Find everything that influenced final value of `fr`.
11001102
let influenced_fr1 = self.dependencies(fr1);
11011103

@@ -1108,23 +1110,23 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11081110
// of dependencies, which doesn't account for the locations of
11091111
// contraints at all. But it will do for now.
11101112
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);
11221124

11231125
relevant_constraint.unwrap_or_else(|| {
11241126
bug!(
11251127
"could not find any constraint to blame for {:?}: {:?}",
11261128
fr1,
1127-
fr2
1129+
elem,
11281130
);
11291131
})
11301132
}

src/librustc_mir/borrow_check/nll/region_infer/values.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::rc::Rc;
1211
use rustc_data_structures::bitvec::SparseBitMatrix;
1312
use rustc_data_structures::fx::FxHashMap;
1413
use rustc_data_structures::indexed_vec::Idx;
1514
use rustc_data_structures::indexed_vec::IndexVec;
1615
use rustc::mir::{BasicBlock, Location, Mir};
1716
use rustc::ty::{self, RegionVid};
17+
use std::fmt::Debug;
18+
use std::rc::Rc;
1819
use syntax::codemap::Span;
1920

2021
use super::{Cause, CauseExt, TrackCauses};
@@ -152,7 +153,7 @@ pub(super) enum RegionElement {
152153
UniversalRegion(RegionVid),
153154
}
154155

155-
pub(super) trait ToElementIndex {
156+
pub(super) trait ToElementIndex: Debug + Copy {
156157
fn to_element_index(self, elements: &RegionValueElements) -> RegionElementIndex;
157158
}
158159

0 commit comments

Comments
 (0)