about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2019-06-03 18:25:21 -0400
committerNiko Matsakis <niko@alum.mit.edu>2019-07-02 12:15:19 -0400
commit09bba9b89d05d3441d8c1acf092e7037e6e11295 (patch)
tree141740b83ea1dbdb58f8c335d3b452938323ff2f
parent7e66a96d586f2f0e25088ef19b455ea56c8aca17 (diff)
downloadrust-09bba9b89d05d3441d8c1acf092e7037e6e11295.tar.gz
rust-09bba9b89d05d3441d8c1acf092e7037e6e11295.zip
introduce `QueryRegionConstraints` struct
-rw-r--r--src/librustc/infer/canonical/mod.rs10
-rw-r--r--src/librustc/infer/canonical/query_response.rs14
-rw-r--r--src/librustc/traits/query/type_op/custom.rs12
-rw-r--r--src/librustc/traits/query/type_op/mod.rs14
-rw-r--r--src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs7
-rw-r--r--src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs4
-rw-r--r--src/librustc_mir/borrow_check/nll/type_check/mod.rs14
7 files changed, 43 insertions, 32 deletions
diff --git a/src/librustc/infer/canonical/mod.rs b/src/librustc/infer/canonical/mod.rs
index 9c616edba9f..f18eeca3610 100644
--- a/src/librustc/infer/canonical/mod.rs
+++ b/src/librustc/infer/canonical/mod.rs
@@ -196,7 +196,15 @@ pub struct QueryResponse<'tcx, R> {
 
 #[derive(Clone, Debug, Default, HashStable)]
 pub struct QueryRegionConstraints<'tcx> {
-    outlives: Vec<QueryOutlivesConstraint<'tcx>>,
+    pub outlives: Vec<QueryOutlivesConstraint<'tcx>>,
+}
+
+impl QueryRegionConstraints<'_> {
+    /// Represents an empty (trivially true) set of region
+    /// constraints.
+    pub fn is_empty(&self) -> bool {
+        self.outlives.is_empty()
+    }
 }
 
 pub type Canonicalized<'tcx, V> = Canonical<'tcx, V>;
diff --git a/src/librustc/infer/canonical/query_response.rs b/src/librustc/infer/canonical/query_response.rs
index acaed189397..b4c46e71b16 100644
--- a/src/librustc/infer/canonical/query_response.rs
+++ b/src/librustc/infer/canonical/query_response.rs
@@ -173,8 +173,8 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
         debug!("ambig_errors = {:#?}", ambig_errors);
 
         let region_obligations = self.take_registered_region_obligations();
-        let outlives_constraints = self.with_region_constraints(|region_constraints| {
-            make_query_outlives(
+        let region_constraints = self.with_region_constraints(|region_constraints| {
+            make_query_region_constraints(
                 tcx,
                 region_obligations
                     .iter()
@@ -191,9 +191,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
 
         Ok(QueryResponse {
             var_values: inference_vars,
-            region_constraints: QueryRegionConstraints {
-                outlives: outlives_constraints,
-            },
+            region_constraints,
             certainty,
             value: answer,
         })
@@ -647,11 +645,11 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
 
 /// Given the region obligations and constraints scraped from the infcx,
 /// creates query region constraints.
-pub fn make_query_outlives<'tcx>(
+pub fn make_query_region_constraints<'tcx>(
     tcx: TyCtxt<'tcx>,
     outlives_obligations: impl Iterator<Item = (Ty<'tcx>, ty::Region<'tcx>)>,
     region_constraints: &RegionConstraintData<'tcx>,
-) -> Vec<QueryOutlivesConstraint<'tcx>> {
+) -> QueryRegionConstraints<'tcx> {
     let RegionConstraintData {
         constraints,
         verifys,
@@ -690,5 +688,5 @@ pub fn make_query_outlives<'tcx>(
         )
         .collect();
 
-    outlives
+    QueryRegionConstraints { outlives }
 }
diff --git a/src/librustc/traits/query/type_op/custom.rs b/src/librustc/traits/query/type_op/custom.rs
index 42d0608d358..a2a5f3f950c 100644
--- a/src/librustc/traits/query/type_op/custom.rs
+++ b/src/librustc/traits/query/type_op/custom.rs
@@ -3,7 +3,7 @@ use std::fmt;
 use crate::traits::query::Fallible;
 
 use crate::infer::canonical::query_response;
-use crate::infer::canonical::QueryOutlivesConstraint;
+use crate::infer::canonical::QueryRegionConstraints;
 use std::rc::Rc;
 use syntax::source_map::DUMMY_SP;
 use crate::traits::{ObligationCause, TraitEngine, TraitEngineExt};
@@ -39,7 +39,7 @@ where
     fn fully_perform(
         self,
         infcx: &InferCtxt<'_, 'tcx>,
-    ) -> Fallible<(Self::Output, Option<Rc<Vec<QueryOutlivesConstraint<'tcx>>>>)> {
+    ) -> Fallible<(Self::Output, Option<Rc<QueryRegionConstraints<'tcx>>>)> {
         if cfg!(debug_assertions) {
             info!("fully_perform({:?})", self);
         }
@@ -62,7 +62,7 @@ where
 fn scrape_region_constraints<'tcx, R>(
     infcx: &InferCtxt<'_, 'tcx>,
     op: impl FnOnce() -> Fallible<InferOk<'tcx, R>>,
-) -> Fallible<(R, Option<Rc<Vec<QueryOutlivesConstraint<'tcx>>>>)> {
+) -> Fallible<(R, Option<Rc<QueryRegionConstraints<'tcx>>>)> {
     let mut fulfill_cx = TraitEngine::new(infcx.tcx);
     let dummy_body_id = ObligationCause::dummy().body_id;
 
@@ -92,7 +92,7 @@ fn scrape_region_constraints<'tcx, R>(
 
     let region_constraint_data = infcx.take_and_reset_region_constraints();
 
-    let outlives = query_response::make_query_outlives(
+    let region_constraints = query_response::make_query_region_constraints(
         infcx.tcx,
         region_obligations
             .iter()
@@ -101,9 +101,9 @@ fn scrape_region_constraints<'tcx, R>(
         &region_constraint_data,
     );
 
-    if outlives.is_empty() {
+    if region_constraints.is_empty() {
         Ok((value, None))
     } else {
-        Ok((value, Some(Rc::new(outlives))))
+        Ok((value, Some(Rc::new(region_constraints))))
     }
 }
diff --git a/src/librustc/traits/query/type_op/mod.rs b/src/librustc/traits/query/type_op/mod.rs
index 0c415876247..bf8cace3a1b 100644
--- a/src/librustc/traits/query/type_op/mod.rs
+++ b/src/librustc/traits/query/type_op/mod.rs
@@ -1,6 +1,6 @@
 use crate::infer::canonical::{
     Canonical, Canonicalized, CanonicalizedQueryResponse, OriginalQueryValues,
-    QueryOutlivesConstraint, QueryResponse,
+    QueryRegionConstraints, QueryOutlivesConstraint, QueryResponse,
 };
 use crate::infer::{InferCtxt, InferOk};
 use std::fmt;
@@ -32,7 +32,7 @@ pub trait TypeOp<'tcx>: Sized + fmt::Debug {
     fn fully_perform(
         self,
         infcx: &InferCtxt<'_, 'tcx>,
-    ) -> Fallible<(Self::Output, Option<Rc<Vec<QueryOutlivesConstraint<'tcx>>>>)>;
+    ) -> Fallible<(Self::Output, Option<Rc<QueryRegionConstraints<'tcx>>>)>;
 }
 
 /// "Query type ops" are type ops that are implemented using a
@@ -140,16 +140,16 @@ where
     fn fully_perform(
         self,
         infcx: &InferCtxt<'_, 'tcx>,
-    ) -> Fallible<(Self::Output, Option<Rc<Vec<QueryOutlivesConstraint<'tcx>>>>)> {
-        let mut qrc = vec![];
-        let r = Q::fully_perform_into(self, infcx, &mut qrc)?;
+    ) -> Fallible<(Self::Output, Option<Rc<QueryRegionConstraints<'tcx>>>)> {
+        let mut outlives = vec![];
+        let r = Q::fully_perform_into(self, infcx, &mut outlives)?;
 
         // Promote the final query-region-constraints into a
         // (optional) ref-counted vector:
-        let opt_qrc = if qrc.is_empty() {
+        let opt_qrc = if outlives.is_empty() {
             None
         } else {
-            Some(Rc::new(qrc))
+            Some(Rc::new(QueryRegionConstraints { outlives }))
         };
 
         Ok((r, opt_qrc))
diff --git a/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs b/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs
index 09ea8dfd61c..2a21da064fa 100644
--- a/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs
+++ b/src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs
@@ -2,7 +2,7 @@ use crate::borrow_check::nll::type_check::constraint_conversion;
 use crate::borrow_check::nll::type_check::{Locations, MirTypeckRegionConstraints};
 use crate::borrow_check::nll::universal_regions::UniversalRegions;
 use crate::borrow_check::nll::ToRegionVid;
-use rustc::infer::canonical::QueryOutlivesConstraint;
+use rustc::infer::canonical::QueryRegionConstraints;
 use rustc::infer::outlives::free_region_map::FreeRegionRelations;
 use rustc::infer::region_constraints::GenericKind;
 use rustc::infer::InferCtxt;
@@ -288,6 +288,7 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
         }
 
         for data in constraint_sets {
+            let QueryRegionConstraints { outlives } = &*data;
             constraint_conversion::ConstraintConversion::new(
                 self.infcx,
                 &self.universal_regions,
@@ -297,7 +298,7 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
                 Locations::All(DUMMY_SP),
                 ConstraintCategory::Internal,
                 &mut self.constraints,
-            ).convert_all(&data);
+            ).convert_all(outlives);
         }
 
         CreateResult {
@@ -311,7 +312,7 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
     /// either the return type of the MIR or one of its arguments. At
     /// the same time, compute and add any implied bounds that come
     /// from this local.
-    fn add_implied_bounds(&mut self, ty: Ty<'tcx>) -> Option<Rc<Vec<QueryOutlivesConstraint<'tcx>>>> {
+    fn add_implied_bounds(&mut self, ty: Ty<'tcx>) -> Option<Rc<QueryRegionConstraints<'tcx>>> {
         debug!("add_implied_bounds(ty={:?})", ty);
         let (bounds, constraints) =
             self.param_env
diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs
index 70441cd258e..f160f658f55 100644
--- a/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs
+++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs
@@ -6,7 +6,7 @@ use crate::borrow_check::nll::type_check::TypeChecker;
 use crate::dataflow::indexes::MovePathIndex;
 use crate::dataflow::move_paths::MoveData;
 use crate::dataflow::{FlowAtLocation, FlowsAtLocation, MaybeInitializedPlaces};
-use rustc::infer::canonical::QueryOutlivesConstraint;
+use rustc::infer::canonical::QueryRegionConstraints;
 use rustc::mir::{BasicBlock, ConstraintCategory, Local, Location, Body};
 use rustc::traits::query::dropck_outlives::DropckOutlivesResult;
 use rustc::traits::query::type_op::outlives::DropckOutlives;
@@ -88,7 +88,7 @@ struct LivenessContext<'me, 'typeck, 'flow, 'tcx> {
 
 struct DropData<'tcx> {
     dropck_result: DropckOutlivesResult<'tcx>,
-    region_constraint_data: Option<Rc<Vec<QueryOutlivesConstraint<'tcx>>>>,
+    region_constraint_data: Option<Rc<QueryRegionConstraints<'tcx>>>,
 }
 
 struct LivenessResults<'me, 'typeck, 'flow, 'tcx> {
diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs
index 134b51c4b79..758c8df1d18 100644
--- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs
@@ -23,7 +23,7 @@ use crate::dataflow::MaybeInitializedPlaces;
 use either::Either;
 use rustc::hir;
 use rustc::hir::def_id::DefId;
-use rustc::infer::canonical::QueryOutlivesConstraint;
+use rustc::infer::canonical::QueryRegionConstraints;
 use rustc::infer::outlives::env::RegionBoundPairs;
 use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime, NLLRegionVariableOrigin};
 use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
@@ -1093,13 +1093,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
         &mut self,
         locations: Locations,
         category: ConstraintCategory,
-        data: &[QueryOutlivesConstraint<'tcx>],
+        data: &QueryRegionConstraints<'tcx>,
     ) {
         debug!(
             "push_region_constraints: constraints generated at {:?} are {:#?}",
             locations, data
         );
 
+        let QueryRegionConstraints { outlives } = data;
+
         constraint_conversion::ConstraintConversion::new(
             self.infcx,
             self.borrowck_context.universal_regions,
@@ -1109,7 +1111,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
             locations,
             category,
             &mut self.borrowck_context.constraints,
-        ).convert_all(&data);
+        ).convert_all(outlives);
     }
 
     /// Convenient wrapper around `relate_tys::relate_types` -- see
@@ -2508,10 +2510,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
         location: Location,
     ) -> ty::InstantiatedPredicates<'tcx> {
         if let Some(closure_region_requirements) = tcx.mir_borrowck(def_id).closure_requirements {
-            let closure_constraints =
-                closure_region_requirements.apply_requirements(tcx, def_id, substs);
+            let closure_constraints = QueryRegionConstraints {
+                outlives: closure_region_requirements.apply_requirements(tcx, def_id, substs)
+            };
 
             let bounds_mapping = closure_constraints
+                .outlives
                 .iter()
                 .enumerate()
                 .filter_map(|(idx, constraint)| {