Skip to content

Commit 0c4062a

Browse files
committed
import trait engine to typeck
1 parent 20703b3 commit 0c4062a

File tree

14 files changed

+38
-35
lines changed

14 files changed

+38
-35
lines changed

src/librustc/infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use ty::{self, Ty, TyCtxt};
2727
use ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric};
2828
use ty::fold::TypeFoldable;
2929
use ty::relate::RelateResult;
30-
use traits::{self, ObligationCause, PredicateObligations, TraitEngine};
30+
use traits::{self, ObligationCause, PredicateObligations};
3131
use rustc_data_structures::unify as ut;
3232
use std::cell::{Cell, RefCell, Ref, RefMut};
3333
use std::collections::BTreeMap;

src/librustc/infer/outlives/bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use infer::InferCtxt;
1212
use syntax::ast;
1313
use syntax::codemap::Span;
14-
use traits::FulfillmentContext;
14+
use traits::{FulfillmentContext, TraitEngine};
1515
use ty::{self, Ty, TypeFoldable};
1616
use ty::outlives::Component;
1717
use ty::wf;

src/librustc/traits/engine.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ use super::{FulfillmentContext, FulfillmentError};
1616
use super::{ObligationCause, PredicateObligation, PendingPredicateObligation};
1717

1818
pub trait TraitEngine<'tcx> {
19-
/// "Normalize" a projection type `<SomeType as SomeTrait>::X` by
20-
/// creating a fresh type variable `$0` as well as a projection
21-
/// predicate `<SomeType as SomeTrait>::X == $0`. When the
22-
/// inference engine runs, it will attempt to find an impl of
23-
/// `SomeTrait` or a where clause that lets us unify `$0` with
24-
/// something concrete. If this fails, we'll unify `$0` with
25-
/// `projection_ty` again.
2619
fn normalize_projection_type<'a, 'gcx>(
2720
&mut self,
2821
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
@@ -31,9 +24,6 @@ pub trait TraitEngine<'tcx> {
3124
cause: ObligationCause<'tcx>,
3225
) -> Ty<'tcx>;
3326

34-
/// Requires that `ty` must implement the trait with `def_id` in
35-
/// the given environment. This trait must not have any type
36-
/// parameters (except for `Self`).
3727
fn register_bound<'a, 'gcx>(
3828
&mut self,
3929
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
@@ -62,8 +52,19 @@ pub trait TraitEngine<'tcx> {
6252
fn pending_obligations(&self) -> Vec<PendingPredicateObligation<'tcx>>;
6353
}
6454

65-
impl<'tcx> dyn TraitEngine<'tcx> {
66-
pub fn new(_tcx: TyCtxt<'_, '_, 'tcx>) -> Box<Self> {
67-
Box::new(FulfillmentContext::new())
68-
}
55+
impl<'a, 'gcx, 'tcx> dyn TraitEngine<'tcx> +'tcx {
56+
pub fn new(_tcx: TyCtxt<'_, '_, 'tcx>) -> Box<Self + 'tcx>
57+
{
58+
Box::new(FulfillmentContext::new())
59+
}
60+
61+
pub fn register_predicate_obligations<I>(&mut self,
62+
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
63+
obligations: I)
64+
where I: IntoIterator<Item = PredicateObligation<'tcx>>
65+
{
66+
for obligation in obligations {
67+
self.register_predicate_obligation(infcx, obligation);
68+
}
69+
}
6970
}

src/librustc/traits/fulfill.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
8585
register_region_obligations: false
8686
}
8787
}
88-
88+
8989
pub fn register_predicate_obligations<I>(&mut self,
9090
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
9191
obligations: I)
@@ -217,8 +217,8 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
217217
}
218218

219219
fn select_all_or_error<'a, 'gcx>(&mut self,
220-
infcx: &InferCtxt<'a, 'gcx, 'tcx>)
221-
-> Result<(),Vec<FulfillmentError<'tcx>>>
220+
infcx: &InferCtxt<'a, 'gcx, 'tcx>)
221+
-> Result<(),Vec<FulfillmentError<'tcx>>>
222222
{
223223
self.select_where_possible(infcx)?;
224224

src/librustc/traits/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub use self::select::{EvaluationCache, SelectionContext, SelectionCache};
4545
pub use self::select::IntercrateAmbiguityCause;
4646
pub use self::specialize::{OverlapError, specialization_graph, translate_substs};
4747
pub use self::specialize::{SpecializesCache, find_associated_item};
48+
pub use self::engine::TraitEngine;
4849
pub use self::util::elaborate_predicates;
4950
pub use self::util::supertraits;
5051
pub use self::util::Supertraits;

src/librustc/traits/specialize/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2626
use hir::def_id::DefId;
2727
use infer::{InferCtxt, InferOk};
2828
use ty::subst::{Subst, Substs};
29-
use traits::{self, ObligationCause};
29+
use traits::{self, ObligationCause, TraitEngine};
3030
use traits::select::IntercrateAmbiguityCause;
3131
use ty::{self, TyCtxt, TypeFoldable};
3232
use syntax_pos::DUMMY_SP;

src/librustc/traits/trans/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use std::marker::PhantomData;
1818
use syntax_pos::DUMMY_SP;
1919
use infer::InferCtxt;
2020
use syntax_pos::Span;
21-
use traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext, TraitEngine, Vtable};
21+
use traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext,
22+
TraitEngine, Vtable};
2223
use ty::{self, Ty, TyCtxt};
2324
use ty::subst::{Subst, Substs};
2425
use ty::fold::TypeFoldable;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use dataflow::move_paths::MoveData;
2020
use rustc::hir::def_id::DefId;
2121
use rustc::infer::{InferCtxt, InferOk, InferResult, LateBoundRegionConversionTime, UnitResult};
2222
use rustc::infer::region_constraints::{GenericKind, RegionConstraintData};
23-
use rustc::traits::{self, Normalized, FulfillmentContext};
23+
use rustc::traits::{self, Normalized, TraitEngine};
2424
use rustc::traits::query::NoSolution;
2525
use rustc::ty::error::TypeError;
2626
use rustc::ty::fold::TypeFoldable;
@@ -662,7 +662,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
662662
where
663663
OP: FnOnce(&mut Self) -> InferResult<'tcx, R>,
664664
{
665-
let mut fulfill_cx = FulfillmentContext::new();
665+
let mut fulfill_cx = TraitEngine::new(self.infcx.tcx);
666666
let InferOk { value, obligations } = self.infcx.commit_if_ok(|_| op(self))?;
667667
fulfill_cx.register_predicate_obligations(self.infcx, obligations);
668668
if let Err(e) = fulfill_cx.select_all_or_error(self.infcx) {

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_data_structures::fx::FxHashSet;
2121
use rustc::hir;
2222
use rustc::hir::def_id::DefId;
2323
use rustc::middle::const_val::ConstVal;
24-
use rustc::traits;
24+
use rustc::traits::{self, TraitEngine};
2525
use rustc::ty::{self, TyCtxt, Ty, TypeFoldable};
2626
use rustc::ty::cast::CastTy;
2727
use rustc::ty::maps::Providers;

src/librustc_traits/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc::infer::InferCtxt;
1212
use rustc::infer::canonical::{CanonicalVarValues, Canonicalize, Certainty, QueryRegionConstraints,
1313
QueryResult};
1414
use rustc::infer::region_constraints::{Constraint, RegionConstraintData};
15-
use rustc::traits::FulfillmentContext;
15+
use rustc::traits::{FulfillmentContext, TraitEngine};
1616
use rustc::traits::query::NoSolution;
1717
use rustc::ty;
1818
use std::fmt::Debug;

0 commit comments

Comments
 (0)