1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 use ty::{self, Ty, TyCtxt};
13 use hir::def_id::DefId;
15 use super::{FulfillmentContext, FulfillmentError};
16 use super::{ObligationCause, PredicateObligation};
18 pub trait TraitEngine<'tcx>: 'tcx {
19 fn normalize_projection_type(
21 infcx: &InferCtxt<'_, 'gcx, 'tcx>,
22 param_env: ty::ParamEnv<'tcx>,
23 projection_ty: ty::ProjectionTy<'tcx>,
24 cause: ObligationCause<'tcx>,
29 infcx: &InferCtxt<'_, 'gcx, 'tcx>,
30 param_env: ty::ParamEnv<'tcx>,
33 cause: ObligationCause<'tcx>,
36 fn register_predicate_obligation(
38 infcx: &InferCtxt<'_, 'gcx, 'tcx>,
39 obligation: PredicateObligation<'tcx>,
42 fn select_all_or_error(
44 infcx: &InferCtxt<'_, 'gcx, 'tcx>,
45 ) -> Result<(), Vec<FulfillmentError<'tcx>>>;
47 fn select_where_possible(
49 infcx: &InferCtxt<'_, 'gcx, 'tcx>,
50 ) -> Result<(), Vec<FulfillmentError<'tcx>>>;
52 fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>>;
55 pub trait TraitEngineExt<'tcx> {
56 fn register_predicate_obligations(
58 infcx: &InferCtxt<'_, 'gcx, 'tcx>,
59 obligations: impl IntoIterator<Item = PredicateObligation<'tcx>>,
63 impl<T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
64 fn register_predicate_obligations(
66 infcx: &InferCtxt<'_, 'gcx, 'tcx>,
67 obligations: impl IntoIterator<Item = PredicateObligation<'tcx>>,
69 for obligation in obligations {
70 self.register_predicate_obligation(infcx, obligation);
75 impl dyn TraitEngine<'tcx> {
76 pub fn new(_tcx: TyCtxt<'_, '_, 'tcx>) -> Box<Self> {
77 Box::new(FulfillmentContext::new())