1 use crate::infer::InferCtxt;
2 use crate::traits::Obligation;
3 use rustc_data_structures::fx::FxHashMap;
4 use rustc_hir::def_id::DefId;
5 use rustc_middle::ty::{self, ToPredicate, Ty};
7 use super::FulfillmentError;
8 use super::{ObligationCause, PredicateObligation};
10 pub trait TraitEngine<'tcx>: 'tcx {
11 fn normalize_projection_type(
13 infcx: &InferCtxt<'tcx>,
14 param_env: ty::ParamEnv<'tcx>,
15 projection_ty: ty::ProjectionTy<'tcx>,
16 cause: ObligationCause<'tcx>,
19 /// Requires that `ty` must implement the trait with `def_id` in
20 /// the given environment. This trait must not have any type
21 /// parameters (except for `Self`).
24 infcx: &InferCtxt<'tcx>,
25 param_env: ty::ParamEnv<'tcx>,
28 cause: ObligationCause<'tcx>,
30 let trait_ref = ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) };
31 self.register_predicate_obligation(
37 predicate: ty::Binder::dummy(trait_ref).without_const().to_predicate(infcx.tcx),
42 fn register_predicate_obligation(
44 infcx: &InferCtxt<'tcx>,
45 obligation: PredicateObligation<'tcx>,
48 fn select_all_or_error(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>>;
50 fn select_where_possible(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>>;
52 fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>>;
54 fn relationships(&mut self) -> &mut FxHashMap<ty::TyVid, ty::FoundRelationships>;
57 pub trait TraitEngineExt<'tcx> {
58 fn register_predicate_obligations(
60 infcx: &InferCtxt<'tcx>,
61 obligations: impl IntoIterator<Item = PredicateObligation<'tcx>>,
65 impl<'tcx, T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
66 fn register_predicate_obligations(
68 infcx: &InferCtxt<'tcx>,
69 obligations: impl IntoIterator<Item = PredicateObligation<'tcx>>,
71 for obligation in obligations {
72 self.register_predicate_obligation(infcx, obligation);