2020-02-22 11:44:18 +01:00
|
|
|
use crate::infer::InferCtxt;
|
|
|
|
use crate::traits::Obligation;
|
2021-04-26 19:00:55 -04:00
|
|
|
use rustc_data_structures::fx::FxHashMap;
|
2020-02-22 11:44:18 +01:00
|
|
|
use rustc_hir::def_id::DefId;
|
2021-12-12 12:34:46 +08:00
|
|
|
use rustc_middle::ty::{self, ToPredicate, Ty};
|
2020-02-22 11:44:18 +01:00
|
|
|
|
|
|
|
use super::FulfillmentError;
|
|
|
|
use super::{ObligationCause, PredicateObligation};
|
|
|
|
|
|
|
|
pub trait TraitEngine<'tcx>: 'tcx {
|
|
|
|
fn normalize_projection_type(
|
|
|
|
&mut self,
|
|
|
|
infcx: &InferCtxt<'_, 'tcx>,
|
|
|
|
param_env: ty::ParamEnv<'tcx>,
|
|
|
|
projection_ty: ty::ProjectionTy<'tcx>,
|
|
|
|
cause: ObligationCause<'tcx>,
|
|
|
|
) -> Ty<'tcx>;
|
|
|
|
|
|
|
|
/// Requires that `ty` must implement the trait with `def_id` in
|
|
|
|
/// the given environment. This trait must not have any type
|
|
|
|
/// parameters (except for `Self`).
|
|
|
|
fn register_bound(
|
|
|
|
&mut self,
|
|
|
|
infcx: &InferCtxt<'_, 'tcx>,
|
|
|
|
param_env: ty::ParamEnv<'tcx>,
|
|
|
|
ty: Ty<'tcx>,
|
|
|
|
def_id: DefId,
|
|
|
|
cause: ObligationCause<'tcx>,
|
|
|
|
) {
|
|
|
|
let trait_ref = ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) };
|
|
|
|
self.register_predicate_obligation(
|
|
|
|
infcx,
|
|
|
|
Obligation {
|
|
|
|
cause,
|
|
|
|
recursion_depth: 0,
|
|
|
|
param_env,
|
2021-09-15 20:54:50 -04:00
|
|
|
predicate: ty::Binder::dummy(trait_ref).without_const().to_predicate(infcx.tcx),
|
2020-02-22 11:44:18 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn register_predicate_obligation(
|
|
|
|
&mut self,
|
|
|
|
infcx: &InferCtxt<'_, 'tcx>,
|
|
|
|
obligation: PredicateObligation<'tcx>,
|
|
|
|
);
|
|
|
|
|
2021-11-08 23:55:51 +08:00
|
|
|
fn select_all_or_error(&mut self, infcx: &InferCtxt<'_, 'tcx>) -> Vec<FulfillmentError<'tcx>>;
|
2020-02-22 11:44:18 +01:00
|
|
|
|
2021-11-29 21:12:53 +08:00
|
|
|
fn select_where_possible(&mut self, infcx: &InferCtxt<'_, 'tcx>)
|
|
|
|
-> Vec<FulfillmentError<'tcx>>;
|
2021-07-26 10:52:17 +08:00
|
|
|
|
2020-02-22 11:44:18 +01:00
|
|
|
fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>>;
|
2021-04-26 19:00:55 -04:00
|
|
|
|
|
|
|
fn relationships(&mut self) -> &mut FxHashMap<ty::TyVid, ty::FoundRelationships>;
|
2020-02-22 11:44:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait TraitEngineExt<'tcx> {
|
|
|
|
fn register_predicate_obligations(
|
|
|
|
&mut self,
|
|
|
|
infcx: &InferCtxt<'_, 'tcx>,
|
|
|
|
obligations: impl IntoIterator<Item = PredicateObligation<'tcx>>,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-13 16:50:58 -05:00
|
|
|
impl<'tcx, T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
|
2020-02-22 11:44:18 +01:00
|
|
|
fn register_predicate_obligations(
|
|
|
|
&mut self,
|
|
|
|
infcx: &InferCtxt<'_, 'tcx>,
|
|
|
|
obligations: impl IntoIterator<Item = PredicateObligation<'tcx>>,
|
|
|
|
) {
|
|
|
|
for obligation in obligations {
|
|
|
|
self.register_predicate_obligation(infcx, obligation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|