Skip to content

Commit e2c0378

Browse files
committed
move related types into the new module
1 parent e4f0368 commit e2c0378

File tree

4 files changed

+57
-52
lines changed

4 files changed

+57
-52
lines changed

src/librustc_mir/borrow_check/nll/constraint_set.rs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
use borrow_check::nll::region_infer::{ConstraintIndex, OutlivesConstraint};
2-
use rustc_data_structures::indexed_vec::IndexVec;
1+
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
32
use rustc_data_structures::fx::FxHashSet;
43
use rustc::ty::RegionVid;
4+
use rustc::mir::Location;
5+
6+
use std::fmt;
7+
use syntax_pos::Span;
58

69
#[derive(Clone, Default)]
710
crate struct ConstraintSet {
@@ -31,3 +34,50 @@ impl ConstraintSet {
3134
}
3235
}
3336

37+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
38+
pub struct OutlivesConstraint {
39+
// NB. The ordering here is not significant for correctness, but
40+
// it is for convenience. Before we dump the constraints in the
41+
// debugging logs, we sort them, and we'd like the "super region"
42+
// to be first, etc. (In particular, span should remain last.)
43+
/// The region SUP must outlive SUB...
44+
pub sup: RegionVid,
45+
46+
/// Region that must be outlived.
47+
pub sub: RegionVid,
48+
49+
/// At this location.
50+
pub point: Location,
51+
52+
/// Later on, we thread the constraints onto a linked list
53+
/// grouped by their `sub` field. So if you had:
54+
///
55+
/// Index | Constraint | Next Field
56+
/// ----- | ---------- | ----------
57+
/// 0 | `'a: 'b` | Some(2)
58+
/// 1 | `'b: 'c` | None
59+
/// 2 | `'c: 'b` | None
60+
pub next: Option<ConstraintIndex>,
61+
62+
/// Where did this constraint arise?
63+
pub span: Span,
64+
}
65+
66+
impl OutlivesConstraint {
67+
pub fn dedup_key(&self) -> (RegionVid, RegionVid) {
68+
(self.sup, self.sub)
69+
}
70+
}
71+
72+
impl fmt::Debug for OutlivesConstraint {
73+
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
74+
write!(
75+
formatter,
76+
"({:?}: {:?} @ {:?}) due to {:?}",
77+
self.sup, self.sub, self.point, self.span
78+
)
79+
}
80+
}
81+
82+
newtype_index!(ConstraintIndex { DEBUG_FORMAT = "ConstraintIndex({})" });
83+

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use rustc_data_structures::indexed_vec::Idx;
1717
use std::borrow::Cow;
1818
use std::io::{self, Write};
1919
use super::*;
20+
use borrow_check::nll::constraint_set::OutlivesConstraint;
21+
2022

2123
impl<'tcx> RegionInferenceContext<'tcx> {
2224
/// Write out the region constraint graph.

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

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use super::universal_regions::UniversalRegions;
1212
use borrow_check::nll::region_infer::values::ToElementIndex;
13-
use borrow_check::nll::constraint_set::ConstraintSet;
13+
use borrow_check::nll::constraint_set::{ConstraintIndex, ConstraintSet, OutlivesConstraint};
1414
use rustc::hir::def_id::DefId;
1515
use rustc::infer::canonical::QueryRegionConstraint;
1616
use rustc::infer::error_reporting::nice_region_error::NiceRegionError;
@@ -26,7 +26,6 @@ use rustc::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable};
2626
use rustc::util::common::{self, ErrorReported};
2727
use rustc_data_structures::bitvec::BitVector;
2828
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
29-
use std::fmt;
3029
use std::rc::Rc;
3130
use syntax_pos::Span;
3231

@@ -115,43 +114,6 @@ pub(crate) enum Cause {
115114
UniversalRegion(RegionVid),
116115
}
117116

118-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
119-
pub struct OutlivesConstraint {
120-
// NB. The ordering here is not significant for correctness, but
121-
// it is for convenience. Before we dump the constraints in the
122-
// debugging logs, we sort them, and we'd like the "super region"
123-
// to be first, etc. (In particular, span should remain last.)
124-
/// The region SUP must outlive SUB...
125-
pub sup: RegionVid,
126-
127-
/// Region that must be outlived.
128-
pub sub: RegionVid,
129-
130-
/// At this location.
131-
pub point: Location,
132-
133-
/// Later on, we thread the constraints onto a linked list
134-
/// grouped by their `sub` field. So if you had:
135-
///
136-
/// Index | Constraint | Next Field
137-
/// ----- | ---------- | ----------
138-
/// 0 | `'a: 'b` | Some(2)
139-
/// 1 | `'b: 'c` | None
140-
/// 2 | `'c: 'b` | None
141-
pub next: Option<ConstraintIndex>,
142-
143-
/// Where did this constraint arise?
144-
pub span: Span,
145-
}
146-
147-
impl OutlivesConstraint {
148-
pub fn dedup_key(&self) -> (RegionVid, RegionVid) {
149-
(self.sup, self.sub)
150-
}
151-
}
152-
153-
newtype_index!(ConstraintIndex { DEBUG_FORMAT = "ConstraintIndex({})" });
154-
155117
/// A "type test" corresponds to an outlives constraint between a type
156118
/// and a lifetime, like `T: 'x` or `<T as Foo>::Bar: 'x`. They are
157119
/// translated from the `Verify` region constraints in the ordinary
@@ -1153,16 +1115,6 @@ impl<'tcx> RegionDefinition<'tcx> {
11531115
}
11541116
}
11551117

1156-
impl fmt::Debug for OutlivesConstraint {
1157-
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
1158-
write!(
1159-
formatter,
1160-
"({:?}: {:?} @ {:?}) due to {:?}",
1161-
self.sup, self.sub, self.point, self.span
1162-
)
1163-
}
1164-
}
1165-
11661118
pub trait ClosureRegionRequirementsExt<'gcx, 'tcx> {
11671119
fn apply_requirements(
11681120
&self,

src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
// except according to those terms.
1010

1111
use borrow_check::location::LocationTable;
12+
use borrow_check::nll::constraint_set::OutlivesConstraint;
1213
use borrow_check::nll::facts::AllFacts;
13-
use borrow_check::nll::region_infer::{OutlivesConstraint, RegionTest, TypeTest};
14+
use borrow_check::nll::region_infer::{RegionTest, TypeTest};
1415
use borrow_check::nll::type_check::Locations;
1516
use borrow_check::nll::universal_regions::UniversalRegions;
1617
use borrow_check::nll::constraint_set::ConstraintSet;

0 commit comments

Comments
 (0)