Skip to content

Commit 8a35601

Browse files
committed
Remove duplicates
1 parent 9f79d2f commit 8a35601

File tree

1 file changed

+32
-5
lines changed
  • src/librustc_mir/borrow_check/nll/region_infer

1 file changed

+32
-5
lines changed

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

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc::mir::{
2424
use rustc::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable};
2525
use rustc::util::common::{self, ErrorReported};
2626
use rustc_data_structures::bitvec::BitVector;
27+
use rustc_data_structures::fx::FxHashSet;
2728
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
2829
use std::fmt;
2930
use std::rc::Rc;
@@ -66,6 +67,7 @@ pub struct RegionInferenceContext<'tcx> {
6667

6768
/// The constraints we have accumulated and used during solving.
6869
constraints: IndexVec<ConstraintIndex, OutlivesConstraint>,
70+
seen_constraints: FxHashSet<(RegionVid, RegionVid)>,
6971

7072
/// Type constraints that we check after solving.
7173
type_tests: Vec<TypeTest<'tcx>>,
@@ -143,6 +145,12 @@ pub struct OutlivesConstraint {
143145
pub span: Span,
144146
}
145147

148+
impl OutlivesConstraint {
149+
fn dedup_key(&self) -> (RegionVid, RegionVid) {
150+
(self.sup, self.sub)
151+
}
152+
}
153+
146154
newtype_index!(ConstraintIndex { DEBUG_FORMAT = "ConstraintIndex({})" });
147155

148156
/// A "type test" corresponds to an outlives constraint between a type
@@ -266,11 +274,16 @@ impl<'tcx> RegionInferenceContext<'tcx> {
266274
liveness_constraints: RegionValues::new(elements, num_region_variables),
267275
inferred_values: None,
268276
dependency_map: None,
269-
constraints: IndexVec::from_raw(outlives_constraints),
277+
constraints: Default::default(),
278+
seen_constraints: Default::default(),
270279
type_tests,
271280
universal_regions,
272281
};
273282

283+
for c in outlives_constraints {
284+
result.add_outlives_iner(c);
285+
}
286+
274287
result.init_universal_regions();
275288

276289
result
@@ -392,15 +405,29 @@ impl<'tcx> RegionInferenceContext<'tcx> {
392405
sub: RegionVid,
393406
point: Location,
394407
) {
395-
debug!("add_outlives({:?}: {:?} @ {:?}", sup, sub, point);
396-
assert!(self.inferred_values.is_none(), "values already inferred");
397-
self.constraints.push(OutlivesConstraint {
408+
self.add_outlives_iner(OutlivesConstraint {
398409
span,
399410
sup,
400411
sub,
401412
point,
402413
next: None,
403-
});
414+
})
415+
}
416+
417+
/// Indicates that the region variable `sup` must outlive `sub` is live at the point `point`.
418+
fn add_outlives_iner(
419+
&mut self,
420+
outlives_constraint: OutlivesConstraint
421+
) {
422+
debug!("add_outlives({:?}: {:?} @ {:?}", outlives_constraint.sup, outlives_constraint.sub, outlives_constraint.point);
423+
assert!(self.inferred_values.is_none(), "values already inferred");
424+
if outlives_constraint.sup == outlives_constraint.sub {
425+
// 'a: 'a is pretty uninteresting
426+
return;
427+
}
428+
if self.seen_constraints.insert(outlives_constraint.dedup_key()) {
429+
self.constraints.push(outlives_constraint);
430+
}
404431
}
405432

406433
/// Perform region inference and report errors if we see any

0 commit comments

Comments
 (0)