about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2018-06-11 11:09:07 -0400
committerNiko Matsakis <niko@alum.mit.edu>2018-06-26 10:59:40 -0400
commitd6136837b770980c8fd271d43358afc455021d9b (patch)
tree0468612d04f3838f8e55056e3e956dc5cf7bed6c
parent4beea9943b541e9165bfcbba8b15f9008a7434d1 (diff)
downloadrust-d6136837b770980c8fd271d43358afc455021d9b.tar.gz
rust-d6136837b770980c8fd271d43358afc455021d9b.zip
convert `predicates` to operate on 1 predicate at a time
-rw-r--r--src/librustc/traits/query/type_op/mod.rs2
-rw-r--r--src/librustc/traits/query/type_op/prove_predicate.rs (renamed from src/librustc/traits/query/type_op/predicates.rs)29
-rw-r--r--src/librustc_mir/borrow_check/nll/type_check/mod.rs29
3 files changed, 23 insertions, 37 deletions
diff --git a/src/librustc/traits/query/type_op/mod.rs b/src/librustc/traits/query/type_op/mod.rs
index 6436e75158e..6cda9ea1518 100644
--- a/src/librustc/traits/query/type_op/mod.rs
+++ b/src/librustc/traits/query/type_op/mod.rs
@@ -23,7 +23,7 @@ pub mod custom;
 pub mod eq;
 pub mod normalize;
 pub mod outlives;
-pub mod predicates;
+pub mod prove_predicate;
 pub mod subtype;
 
 pub trait TypeOp<'gcx, 'tcx>: Sized + fmt::Debug {
diff --git a/src/librustc/traits/query/type_op/predicates.rs b/src/librustc/traits/query/type_op/prove_predicate.rs
index d729ce1e0eb..7dacf6a7dea 100644
--- a/src/librustc/traits/query/type_op/predicates.rs
+++ b/src/librustc/traits/query/type_op/prove_predicate.rs
@@ -9,43 +9,36 @@
 // except according to those terms.
 
 use infer::{InferCtxt, InferOk, InferResult};
-use traits::{Obligation, ObligationCause, PredicateObligation};
+use traits::{Obligation, ObligationCause};
 use ty::{ParamEnv, Predicate, TyCtxt};
 
 #[derive(Debug)]
-pub struct ProvePredicates<'tcx> {
-    obligations: Vec<PredicateObligation<'tcx>>,
+pub struct ProvePredicate<'tcx> {
+    param_env: ParamEnv<'tcx>,
+    predicate: Predicate<'tcx>,
 }
 
-impl<'tcx> ProvePredicates<'tcx> {
+impl<'tcx> ProvePredicate<'tcx> {
     pub fn new(
         param_env: ParamEnv<'tcx>,
-        predicates: impl IntoIterator<Item = Predicate<'tcx>>,
+        predicate: Predicate<'tcx>,
     ) -> Self {
-        ProvePredicates {
-            obligations: predicates
-                .into_iter()
-                .map(|p| Obligation::new(ObligationCause::dummy(), param_env, p))
-                .collect(),
-        }
+        ProvePredicate { param_env, predicate }
     }
 }
 
-impl<'gcx, 'tcx> super::TypeOp<'gcx, 'tcx> for ProvePredicates<'tcx> {
+impl<'gcx, 'tcx> super::TypeOp<'gcx, 'tcx> for ProvePredicate<'tcx> {
     type Output = ();
 
     fn trivial_noop(self, _tcx: TyCtxt<'_, 'gcx, 'tcx>) -> Result<Self::Output, Self> {
-        if self.obligations.is_empty() {
-            Ok(())
-        } else {
-            Err(self)
-        }
+        Err(self)
     }
 
     fn perform(self, _infcx: &InferCtxt<'_, 'gcx, 'tcx>) -> InferResult<'tcx, Self::Output> {
+        let obligation = Obligation::new(ObligationCause::dummy(), self.param_env, self.predicate);
         Ok(InferOk {
             value: (),
-            obligations: self.obligations,
+            obligations: vec![obligation],
         })
     }
 }
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 865ee66cccf..1f45a8ba173 100644
--- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs
@@ -1545,26 +1545,19 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
         predicates: impl IntoIterator<Item = ty::Predicate<'tcx>> + Clone,
         location: Location,
     ) {
-        // This intermediate vector is mildly unfortunate, in that we
-        // sometimes create it even when logging is disabled, but only
-        // if debug-info is enabled, and I doubt it is actually
-        // expensive. -nmatsakis
-        let predicates_vec: Vec<_> = if cfg!(debug_assertions) {
-            predicates.clone().into_iter().collect()
-        } else {
-            Vec::new()
-        };
 
-        debug!(
-            "prove_predicates(predicates={:?}, location={:?})",
-            predicates_vec, location,
-        );
+        for predicate in predicates {
+            debug!(
+                "prove_predicates(predicate={:?}, location={:?})",
+                predicate, location,
+            );
 
-        let param_env = self.param_env;
-        self.fully_perform_op(
-            location.at_self(),
-            type_op::predicates::ProvePredicates::new(param_env, predicates),
-        ).unwrap()
+            let param_env = self.param_env;
+            self.fully_perform_op(
+                location.at_self(),
+                type_op::prove_predicate::ProvePredicate::new(param_env, predicate),
+            ).unwrap()
+        }
     }
 
     fn typeck_mir(&mut self, mir: &Mir<'tcx>) {