diff --git a/Cargo.lock b/Cargo.lock index 69b582cd8fb..f31ef938183 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3852,6 +3852,7 @@ dependencies = [ "rustc_session", "rustc_span", "rustc_target", + "serialize", "smallvec 1.0.0", ] diff --git a/src/librustc_infer/Cargo.toml b/src/librustc_infer/Cargo.toml index bc4080ac6c8..fa8e5a2ab78 100644 --- a/src/librustc_infer/Cargo.toml +++ b/src/librustc_infer/Cargo.toml @@ -19,6 +19,7 @@ rustc_hir = { path = "../librustc_hir" } rustc_index = { path = "../librustc_index" } rustc_macros = { path = "../librustc_macros" } rustc_session = { path = "../librustc_session" } +rustc_serialize = { path = "../libserialize", package = "serialize" } rustc_span = { path = "../librustc_span" } rustc_target = { path = "../librustc_target" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } diff --git a/src/librustc_middle/ty/free_region_map.rs b/src/librustc_infer/infer/free_regions.rs similarity index 74% rename from src/librustc_middle/ty/free_region_map.rs rename to src/librustc_infer/infer/free_regions.rs index 2ab12a4acbf..e31c524c197 100644 --- a/src/librustc_middle/ty/free_region_map.rs +++ b/src/librustc_infer/infer/free_regions.rs @@ -1,5 +1,47 @@ -use crate::ty::{self, Lift, Region, TyCtxt}; +//! This module handles the relationships between "free regions", i.e., lifetime parameters. +//! Ordinarily, free regions are unrelated to one another, but they can be related via implied +//! or explicit bounds. In that case, we track the bounds using the `TransitiveRelation` type, +//! and use that to decide when one free region outlives another, and so forth. + use rustc_data_structures::transitive_relation::TransitiveRelation; +use rustc_hir::def_id::DefId; +use rustc_middle::middle::region; +use rustc_middle::ty::{self, Lift, Region, TyCtxt}; + +/// Combines a `region::ScopeTree` (which governs relationships between +/// scopes) and a `FreeRegionMap` (which governs relationships between +/// free regions) to yield a complete relation between concrete +/// regions. +/// +/// This stuff is a bit convoluted and should be refactored, but as we +/// transition to NLL, it'll all go away anyhow. +pub struct RegionRelations<'a, 'tcx> { + pub tcx: TyCtxt<'tcx>, + + /// The context used to fetch the region maps. + pub context: DefId, + + /// The region maps for the given context. + pub region_scope_tree: &'a region::ScopeTree, + + /// Free-region relationships. + pub free_regions: &'a FreeRegionMap<'tcx>, +} + +impl<'a, 'tcx> RegionRelations<'a, 'tcx> { + pub fn new( + tcx: TyCtxt<'tcx>, + context: DefId, + region_scope_tree: &'a region::ScopeTree, + free_regions: &'a FreeRegionMap<'tcx>, + ) -> Self { + Self { tcx, context, region_scope_tree, free_regions } + } + + pub fn lub_free_regions(&self, r_a: Region<'tcx>, r_b: Region<'tcx>) -> Region<'tcx> { + self.free_regions.lub_free_regions(self.tcx, r_a, r_b) + } +} #[derive(Clone, RustcEncodable, RustcDecodable, Debug, Default, HashStable)] pub struct FreeRegionMap<'tcx> { diff --git a/src/librustc_infer/infer/lexical_region_resolve/graphviz.rs b/src/librustc_infer/infer/lexical_region_resolve/graphviz.rs index 141424fc0c7..5d3e8f440d6 100644 --- a/src/librustc_infer/infer/lexical_region_resolve/graphviz.rs +++ b/src/librustc_infer/infer/lexical_region_resolve/graphviz.rs @@ -10,10 +10,10 @@ use graphviz as dot; use super::Constraint; use crate::infer::region_constraints::RegionConstraintData; +use crate::infer::RegionRelations; use crate::infer::SubregionOrigin; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::def_id::DefIndex; -use rustc_middle::middle::free_region::RegionRelations; use rustc_middle::middle::region; use rustc_middle::ty; diff --git a/src/librustc_infer/infer/lexical_region_resolve/mod.rs b/src/librustc_infer/infer/lexical_region_resolve/mod.rs index c8d35774978..3ff0e26a4dc 100644 --- a/src/librustc_infer/infer/lexical_region_resolve/mod.rs +++ b/src/librustc_infer/infer/lexical_region_resolve/mod.rs @@ -6,6 +6,7 @@ use crate::infer::region_constraints::MemberConstraint; use crate::infer::region_constraints::RegionConstraintData; use crate::infer::region_constraints::VarInfos; use crate::infer::region_constraints::VerifyBound; +use crate::infer::RegionRelations; use crate::infer::RegionVariableOrigin; use crate::infer::RegionckMode; use crate::infer::SubregionOrigin; @@ -14,7 +15,6 @@ use rustc_data_structures::graph::implementation::{ Direction, Graph, NodeIndex, INCOMING, OUTGOING, }; use rustc_index::vec::{Idx, IndexVec}; -use rustc_middle::middle::free_region::RegionRelations; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{ReEarlyBound, ReEmpty, ReErased, ReFree, ReStatic}; diff --git a/src/librustc_infer/infer/mod.rs b/src/librustc_infer/infer/mod.rs index edaa7a04b34..8e6a66efac4 100644 --- a/src/librustc_infer/infer/mod.rs +++ b/src/librustc_infer/infer/mod.rs @@ -18,7 +18,6 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues}; use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue}; use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType}; -use rustc_middle::middle::free_region::RegionRelations; use rustc_middle::middle::region; use rustc_middle::mir; use rustc_middle::mir::interpret::ConstEvalResult; @@ -39,6 +38,7 @@ use std::collections::BTreeMap; use std::fmt; use self::combine::CombineFields; +use self::free_regions::RegionRelations; use self::lexical_region_resolve::LexicalRegionResolutions; use self::outlives::env::OutlivesEnvironment; use self::region_constraints::{GenericKind, RegionConstraintData, VarInfos, VerifyBound}; @@ -50,6 +50,7 @@ pub mod canonical; mod combine; mod equate; pub mod error_reporting; +pub mod free_regions; mod freshen; mod fudge; mod glb; diff --git a/src/librustc_infer/infer/outlives/env.rs b/src/librustc_infer/infer/outlives/env.rs index 06a23269389..1a9e20e79fe 100644 --- a/src/librustc_infer/infer/outlives/env.rs +++ b/src/librustc_infer/infer/outlives/env.rs @@ -1,9 +1,9 @@ +use crate::infer::free_regions::FreeRegionMap; use crate::infer::{GenericKind, InferCtxt}; use crate::traits::query::OutlivesBound; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; use rustc_middle::ty; -use rustc_middle::ty::free_region_map::FreeRegionMap; use super::explicit_outlives_bounds; diff --git a/src/librustc_middle/middle/free_region.rs b/src/librustc_middle/middle/free_region.rs deleted file mode 100644 index 62ccd946744..00000000000 --- a/src/librustc_middle/middle/free_region.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! This module handles the relationships between "free regions", i.e., lifetime parameters. -//! Ordinarily, free regions are unrelated to one another, but they can be related via implied -//! or explicit bounds. In that case, we track the bounds using the `TransitiveRelation` type, -//! and use that to decide when one free region outlives another, and so forth. - -use crate::middle::region; -use crate::ty::free_region_map::FreeRegionMap; -use crate::ty::{Region, TyCtxt}; -use rustc_hir::def_id::DefId; - -/// Combines a `region::ScopeTree` (which governs relationships between -/// scopes) and a `FreeRegionMap` (which governs relationships between -/// free regions) to yield a complete relation between concrete -/// regions. -/// -/// This stuff is a bit convoluted and should be refactored, but as we -/// transition to NLL, it'll all go away anyhow. -pub struct RegionRelations<'a, 'tcx> { - pub tcx: TyCtxt<'tcx>, - - /// The context used to fetch the region maps. - pub context: DefId, - - /// The region maps for the given context. - pub region_scope_tree: &'a region::ScopeTree, - - /// Free-region relationships. - pub free_regions: &'a FreeRegionMap<'tcx>, -} - -impl<'a, 'tcx> RegionRelations<'a, 'tcx> { - pub fn new( - tcx: TyCtxt<'tcx>, - context: DefId, - region_scope_tree: &'a region::ScopeTree, - free_regions: &'a FreeRegionMap<'tcx>, - ) -> Self { - Self { tcx, context, region_scope_tree, free_regions } - } - - pub fn lub_free_regions(&self, r_a: Region<'tcx>, r_b: Region<'tcx>) -> Region<'tcx> { - self.free_regions.lub_free_regions(self.tcx, r_a, r_b) - } -} diff --git a/src/librustc_middle/middle/mod.rs b/src/librustc_middle/middle/mod.rs index 464488964af..9bc9ca6707a 100644 --- a/src/librustc_middle/middle/mod.rs +++ b/src/librustc_middle/middle/mod.rs @@ -2,7 +2,6 @@ pub mod codegen_fn_attrs; pub mod cstore; pub mod dependency_format; pub mod exported_symbols; -pub mod free_region; pub mod lang_items; pub mod lib_features { use rustc_data_structures::fx::{FxHashMap, FxHashSet}; diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 73e7e623b12..b955ce91e59 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -96,7 +96,6 @@ pub mod error; pub mod fast_reject; pub mod flags; pub mod fold; -pub mod free_region_map; pub mod inhabitedness; pub mod layout; pub mod normalize_erasing_regions; diff --git a/src/librustc_mir/borrow_check/type_check/free_region_relations.rs b/src/librustc_mir/borrow_check/type_check/free_region_relations.rs index 0583295bfca..f97dff14645 100644 --- a/src/librustc_mir/borrow_check/type_check/free_region_relations.rs +++ b/src/librustc_mir/borrow_check/type_check/free_region_relations.rs @@ -1,12 +1,12 @@ use rustc_data_structures::frozen::Frozen; use rustc_data_structures::transitive_relation::TransitiveRelation; use rustc_infer::infer::canonical::QueryRegionConstraints; +use rustc_infer::infer::free_regions::FreeRegionRelations; use rustc_infer::infer::outlives; use rustc_infer::infer::region_constraints::GenericKind; use rustc_infer::infer::InferCtxt; use rustc_middle::mir::ConstraintCategory; use rustc_middle::traits::query::OutlivesBound; -use rustc_middle::ty::free_region_map::FreeRegionRelations; use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt}; use rustc_span::DUMMY_SP; use rustc_trait_selection::traits::query::type_op::{self, TypeOp}; diff --git a/src/librustc_trait_selection/opaque_types.rs b/src/librustc_trait_selection/opaque_types.rs index f67b8b87ced..b464a576950 100644 --- a/src/librustc_trait_selection/opaque_types.rs +++ b/src/librustc_trait_selection/opaque_types.rs @@ -6,10 +6,10 @@ use rustc_hir as hir; use rustc_hir::def_id::{DefId, DefIdMap}; use rustc_hir::Node; use rustc_infer::infer::error_reporting::unexpected_hidden_region_diagnostic; +use rustc_infer::infer::free_regions::FreeRegionRelations; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::{self, InferCtxt, InferOk}; use rustc_middle::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor}; -use rustc_middle::ty::free_region_map::FreeRegionRelations; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef}; use rustc_middle::ty::{self, GenericParamDefKind, Ty, TyCtxt}; use rustc_session::config::nightly_options;