From e2c0378a63041e8c2696760039b9117251dbee30 Mon Sep 17 00:00:00 2001 From: Eh2406 Date: Wed, 27 Jun 2018 16:46:27 -0400 Subject: [PATCH] move related types into the new module --- .../borrow_check/nll/constraint_set.rs | 54 ++++++++++++++++++- .../borrow_check/nll/region_infer/graphviz.rs | 2 + .../borrow_check/nll/region_infer/mod.rs | 50 +---------------- .../nll/type_check/constraint_conversion.rs | 3 +- 4 files changed, 57 insertions(+), 52 deletions(-) diff --git a/src/librustc_mir/borrow_check/nll/constraint_set.rs b/src/librustc_mir/borrow_check/nll/constraint_set.rs index 4b0a0c9bce9..5d4ffc8f4fd 100644 --- a/src/librustc_mir/borrow_check/nll/constraint_set.rs +++ b/src/librustc_mir/borrow_check/nll/constraint_set.rs @@ -1,7 +1,10 @@ -use borrow_check::nll::region_infer::{ConstraintIndex, OutlivesConstraint}; -use rustc_data_structures::indexed_vec::IndexVec; +use rustc_data_structures::indexed_vec::{Idx, IndexVec}; use rustc_data_structures::fx::FxHashSet; use rustc::ty::RegionVid; +use rustc::mir::Location; + +use std::fmt; +use syntax_pos::Span; #[derive(Clone, Default)] crate struct ConstraintSet { @@ -31,3 +34,50 @@ impl ConstraintSet { } } +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct OutlivesConstraint { + // NB. The ordering here is not significant for correctness, but + // it is for convenience. Before we dump the constraints in the + // debugging logs, we sort them, and we'd like the "super region" + // to be first, etc. (In particular, span should remain last.) + /// The region SUP must outlive SUB... + pub sup: RegionVid, + + /// Region that must be outlived. + pub sub: RegionVid, + + /// At this location. + pub point: Location, + + /// Later on, we thread the constraints onto a linked list + /// grouped by their `sub` field. So if you had: + /// + /// Index | Constraint | Next Field + /// ----- | ---------- | ---------- + /// 0 | `'a: 'b` | Some(2) + /// 1 | `'b: 'c` | None + /// 2 | `'c: 'b` | None + pub next: Option, + + /// Where did this constraint arise? + pub span: Span, +} + +impl OutlivesConstraint { + pub fn dedup_key(&self) -> (RegionVid, RegionVid) { + (self.sup, self.sub) + } +} + +impl fmt::Debug for OutlivesConstraint { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + write!( + formatter, + "({:?}: {:?} @ {:?}) due to {:?}", + self.sup, self.sub, self.point, self.span + ) + } +} + +newtype_index!(ConstraintIndex { DEBUG_FORMAT = "ConstraintIndex({})" }); + diff --git a/src/librustc_mir/borrow_check/nll/region_infer/graphviz.rs b/src/librustc_mir/borrow_check/nll/region_infer/graphviz.rs index ad15a435359..78ec60baa87 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/graphviz.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/graphviz.rs @@ -17,6 +17,8 @@ use rustc_data_structures::indexed_vec::Idx; use std::borrow::Cow; use std::io::{self, Write}; use super::*; +use borrow_check::nll::constraint_set::OutlivesConstraint; + impl<'tcx> RegionInferenceContext<'tcx> { /// Write out the region constraint graph. diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index 5da486815e1..0f6c98920d7 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -10,7 +10,7 @@ use super::universal_regions::UniversalRegions; use borrow_check::nll::region_infer::values::ToElementIndex; -use borrow_check::nll::constraint_set::ConstraintSet; +use borrow_check::nll::constraint_set::{ConstraintIndex, ConstraintSet, OutlivesConstraint}; use rustc::hir::def_id::DefId; use rustc::infer::canonical::QueryRegionConstraint; use rustc::infer::error_reporting::nice_region_error::NiceRegionError; @@ -26,7 +26,6 @@ use rustc::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable}; use rustc::util::common::{self, ErrorReported}; use rustc_data_structures::bitvec::BitVector; use rustc_data_structures::indexed_vec::{Idx, IndexVec}; -use std::fmt; use std::rc::Rc; use syntax_pos::Span; @@ -115,43 +114,6 @@ pub(crate) enum Cause { UniversalRegion(RegionVid), } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct OutlivesConstraint { - // NB. The ordering here is not significant for correctness, but - // it is for convenience. Before we dump the constraints in the - // debugging logs, we sort them, and we'd like the "super region" - // to be first, etc. (In particular, span should remain last.) - /// The region SUP must outlive SUB... - pub sup: RegionVid, - - /// Region that must be outlived. - pub sub: RegionVid, - - /// At this location. - pub point: Location, - - /// Later on, we thread the constraints onto a linked list - /// grouped by their `sub` field. So if you had: - /// - /// Index | Constraint | Next Field - /// ----- | ---------- | ---------- - /// 0 | `'a: 'b` | Some(2) - /// 1 | `'b: 'c` | None - /// 2 | `'c: 'b` | None - pub next: Option, - - /// Where did this constraint arise? - pub span: Span, -} - -impl OutlivesConstraint { - pub fn dedup_key(&self) -> (RegionVid, RegionVid) { - (self.sup, self.sub) - } -} - -newtype_index!(ConstraintIndex { DEBUG_FORMAT = "ConstraintIndex({})" }); - /// A "type test" corresponds to an outlives constraint between a type /// and a lifetime, like `T: 'x` or `::Bar: 'x`. They are /// translated from the `Verify` region constraints in the ordinary @@ -1153,16 +1115,6 @@ impl<'tcx> RegionDefinition<'tcx> { } } -impl fmt::Debug for OutlivesConstraint { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - write!( - formatter, - "({:?}: {:?} @ {:?}) due to {:?}", - self.sup, self.sub, self.point, self.span - ) - } -} - pub trait ClosureRegionRequirementsExt<'gcx, 'tcx> { fn apply_requirements( &self, diff --git a/src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs b/src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs index 263dd334e78..3100df3e8f6 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs @@ -9,8 +9,9 @@ // except according to those terms. use borrow_check::location::LocationTable; +use borrow_check::nll::constraint_set::OutlivesConstraint; use borrow_check::nll::facts::AllFacts; -use borrow_check::nll::region_infer::{OutlivesConstraint, RegionTest, TypeTest}; +use borrow_check::nll::region_infer::{RegionTest, TypeTest}; use borrow_check::nll::type_check::Locations; use borrow_check::nll::universal_regions::UniversalRegions; use borrow_check::nll::constraint_set::ConstraintSet;