Skip to content

Commit ef84523

Browse files
committed
convert predicates to operate on 1 predicate at a time
1 parent 4690fbf commit ef84523

File tree

3 files changed

+23
-37
lines changed

3 files changed

+23
-37
lines changed

src/librustc/traits/query/type_op/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub mod custom;
2323
pub mod eq;
2424
pub mod normalize;
2525
pub mod outlives;
26-
pub mod predicates;
26+
pub mod prove_predicate;
2727
pub mod subtype;
2828

2929
pub trait TypeOp<'gcx, 'tcx>: Sized + fmt::Debug {

src/librustc/traits/query/type_op/predicates.rs renamed to src/librustc/traits/query/type_op/prove_predicate.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,36 @@
99
// except according to those terms.
1010

1111
use infer::{InferCtxt, InferOk, InferResult};
12-
use traits::{Obligation, ObligationCause, PredicateObligation};
12+
use traits::{Obligation, ObligationCause};
1313
use ty::{ParamEnv, Predicate, TyCtxt};
1414

1515
#[derive(Debug)]
16-
pub struct ProvePredicates<'tcx> {
17-
obligations: Vec<PredicateObligation<'tcx>>,
16+
pub struct ProvePredicate<'tcx> {
17+
param_env: ParamEnv<'tcx>,
18+
predicate: Predicate<'tcx>,
1819
}
1920

20-
impl<'tcx> ProvePredicates<'tcx> {
21+
impl<'tcx> ProvePredicate<'tcx> {
2122
pub fn new(
2223
param_env: ParamEnv<'tcx>,
23-
predicates: impl IntoIterator<Item = Predicate<'tcx>>,
24+
predicate: Predicate<'tcx>,
2425
) -> Self {
25-
ProvePredicates {
26-
obligations: predicates
27-
.into_iter()
28-
.map(|p| Obligation::new(ObligationCause::dummy(), param_env, p))
29-
.collect(),
30-
}
26+
ProvePredicate { param_env, predicate }
3127
}
3228
}
3329

34-
impl<'gcx, 'tcx> super::TypeOp<'gcx, 'tcx> for ProvePredicates<'tcx> {
30+
impl<'gcx, 'tcx> super::TypeOp<'gcx, 'tcx> for ProvePredicate<'tcx> {
3531
type Output = ();
3632

3733
fn trivial_noop(self, _tcx: TyCtxt<'_, 'gcx, 'tcx>) -> Result<Self::Output, Self> {
38-
if self.obligations.is_empty() {
39-
Ok(())
40-
} else {
41-
Err(self)
42-
}
34+
Err(self)
4335
}
4436

4537
fn perform(self, _infcx: &InferCtxt<'_, 'gcx, 'tcx>) -> InferResult<'tcx, Self::Output> {
38+
let obligation = Obligation::new(ObligationCause::dummy(), self.param_env, self.predicate);
4639
Ok(InferOk {
4740
value: (),
48-
obligations: self.obligations,
41+
obligations: vec![obligation],
4942
})
5043
}
5144
}

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

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,26 +1545,19 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
15451545
predicates: impl IntoIterator<Item = ty::Predicate<'tcx>> + Clone,
15461546
location: Location,
15471547
) {
1548-
// This intermediate vector is mildly unfortunate, in that we
1549-
// sometimes create it even when logging is disabled, but only
1550-
// if debug-info is enabled, and I doubt it is actually
1551-
// expensive. -nmatsakis
1552-
let predicates_vec: Vec<_> = if cfg!(debug_assertions) {
1553-
predicates.clone().into_iter().collect()
1554-
} else {
1555-
Vec::new()
1556-
};
15571548

1558-
debug!(
1559-
"prove_predicates(predicates={:?}, location={:?})",
1560-
predicates_vec, location,
1561-
);
1549+
for predicate in predicates {
1550+
debug!(
1551+
"prove_predicates(predicate={:?}, location={:?})",
1552+
predicate, location,
1553+
);
15621554

1563-
let param_env = self.param_env;
1564-
self.fully_perform_op(
1565-
location.at_self(),
1566-
type_op::predicates::ProvePredicates::new(param_env, predicates),
1567-
).unwrap()
1555+
let param_env = self.param_env;
1556+
self.fully_perform_op(
1557+
location.at_self(),
1558+
type_op::prove_predicate::ProvePredicate::new(param_env, predicate),
1559+
).unwrap()
1560+
}
15681561
}
15691562

15701563
fn typeck_mir(&mut self, mir: &Mir<'tcx>) {

0 commit comments

Comments
 (0)