Skip to content

Commit 9bd2a63

Browse files
committed
remove inner_mut as it can mess up invariants
1 parent 497a3b4 commit 9bd2a63

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

src/librustc_mir/borrow_check/nll/constraint_set.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,39 @@ crate struct ConstraintSet {
2323
}
2424

2525
impl ConstraintSet {
26-
pub fn push(&mut self, outlives_constraint: OutlivesConstraint) {
26+
pub fn new() -> Self {
27+
Default::default()
28+
}
29+
30+
pub fn push(&mut self, constraint: OutlivesConstraint) {
2731
debug!("add_outlives({:?}: {:?} @ {:?}",
28-
outlives_constraint.sup,
29-
outlives_constraint.sub,
30-
outlives_constraint.point);
31-
if outlives_constraint.sup == outlives_constraint.sub {
32+
constraint.sup,
33+
constraint.sub,
34+
constraint.point);
35+
if constraint.sup == constraint.sub {
3236
// 'a: 'a is pretty uninteresting
3337
return;
3438
}
35-
if self.seen_constraints.insert(outlives_constraint.dedup_key()) {
36-
self.constraints.push(outlives_constraint);
39+
if self.seen_constraints.insert(constraint.dedup_key()) {
40+
self.constraints.push(constraint);
3741
}
3842
}
3943

4044
pub fn inner(&self) -> &IndexVec<ConstraintIndex, OutlivesConstraint> {
4145
&self.constraints
4246
}
4347

44-
/// Do Not use this to add nor remove items to the Vec,
45-
/// nor change the `sup`,
46-
/// nor `sub` of the data.
47-
pub fn inner_mut(&mut self) -> &mut IndexVec<ConstraintIndex, OutlivesConstraint> {
48-
&mut self.constraints
48+
pub fn link(&mut self, len: usize) -> IndexVec<RegionVid, Option<ConstraintIndex>> {
49+
let mut map = IndexVec::from_elem_n(None, len);
50+
51+
for (idx, constraint) in self.constraints.iter_enumerated_mut().rev() {
52+
let mut head = &mut map[constraint.sub];
53+
debug_assert!(constraint.next.is_none());
54+
constraint.next = *head;
55+
*head = Some(idx);
56+
}
57+
58+
map
4959
}
5060
}
5161

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -486,16 +486,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
486486
/// These are constraints like Y: X @ P -- so if X changed, we may
487487
/// need to grow Y.
488488
fn build_dependency_map(&mut self) -> IndexVec<RegionVid, Option<ConstraintIndex>> {
489-
let mut map = IndexVec::from_elem(None, &self.definitions);
490-
491-
for (idx, constraint) in self.constraints.inner_mut().iter_enumerated_mut().rev() {
492-
let mut head = &mut map[constraint.sub];
493-
debug_assert!(constraint.next.is_none());
494-
constraint.next = *head;
495-
*head = Some(idx);
496-
}
497-
498-
map
489+
self.constraints.link(self.definitions.len())
499490
}
500491

501492
/// Once regions have been propagated, this method is used to see

0 commit comments

Comments
 (0)