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 /// Requires that `ty` must implement the trait with `def_id` in
12 /// the given environment. This trait must not have any type
13 /// parameters (except for `Self`).
16 infcx: &InferCtxt<'tcx>,
17 param_env: ty::ParamEnv<'tcx>,
20 cause: ObligationCause<'tcx>,
22 let trait_ref = infcx.tcx.mk_trait_ref(def_id, [ty]);
23 self.register_predicate_obligation(
29 predicate: ty::Binder::dummy(trait_ref).without_const().to_predicate(infcx.tcx),
34 fn register_predicate_obligation(
36 infcx: &InferCtxt<'tcx>,
37 obligation: PredicateObligation<'tcx>,
40 fn select_all_or_error(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>>;
42 fn select_where_possible(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>>;
44 fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>>;
46 fn relationships(&mut self) -> &mut FxHashMap<ty::TyVid, ty::FoundRelationships>;
49 pub trait TraitEngineExt<'tcx> {
50 fn register_predicate_obligations(
52 infcx: &InferCtxt<'tcx>,
53 obligations: impl IntoIterator<Item = PredicateObligation<'tcx>>,
57 impl<'tcx, T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
58 fn register_predicate_obligations(
60 infcx: &InferCtxt<'tcx>,
61 obligations: impl IntoIterator<Item = PredicateObligation<'tcx>>,
63 for obligation in obligations {
64 self.register_predicate_obligation(infcx, obligation);