2018-03-11 02:29:22 +00:00
|
|
|
use infer::InferCtxt;
|
|
|
|
use ty::{self, Ty, TyCtxt};
|
|
|
|
use hir::def_id::DefId;
|
|
|
|
|
|
|
|
use super::{FulfillmentContext, FulfillmentError};
|
2018-04-19 05:13:20 +00:00
|
|
|
use super::{ObligationCause, PredicateObligation};
|
2018-03-11 02:29:22 +00:00
|
|
|
|
2018-03-22 16:21:38 +00:00
|
|
|
pub trait TraitEngine<'tcx>: 'tcx {
|
2018-06-27 20:04:32 +00:00
|
|
|
fn normalize_projection_type(
|
2018-03-11 02:29:22 +00:00
|
|
|
&mut self,
|
2018-06-27 20:04:32 +00:00
|
|
|
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
|
2018-03-11 02:29:22 +00:00
|
|
|
param_env: ty::ParamEnv<'tcx>,
|
|
|
|
projection_ty: ty::ProjectionTy<'tcx>,
|
|
|
|
cause: ObligationCause<'tcx>,
|
|
|
|
) -> Ty<'tcx>;
|
|
|
|
|
2018-06-27 20:04:32 +00:00
|
|
|
fn register_bound(
|
2018-03-11 02:29:22 +00:00
|
|
|
&mut self,
|
2018-06-27 20:04:32 +00:00
|
|
|
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
|
2018-03-11 02:29:22 +00:00
|
|
|
param_env: ty::ParamEnv<'tcx>,
|
|
|
|
ty: Ty<'tcx>,
|
|
|
|
def_id: DefId,
|
|
|
|
cause: ObligationCause<'tcx>,
|
|
|
|
);
|
|
|
|
|
2018-06-27 20:04:32 +00:00
|
|
|
fn register_predicate_obligation(
|
2018-03-11 02:29:22 +00:00
|
|
|
&mut self,
|
2018-06-27 20:04:32 +00:00
|
|
|
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
|
2018-03-11 02:29:22 +00:00
|
|
|
obligation: PredicateObligation<'tcx>,
|
|
|
|
);
|
|
|
|
|
2018-06-27 20:04:32 +00:00
|
|
|
fn select_all_or_error(
|
2018-03-11 02:29:22 +00:00
|
|
|
&mut self,
|
2018-06-27 20:04:32 +00:00
|
|
|
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
|
2018-03-11 02:29:22 +00:00
|
|
|
) -> Result<(), Vec<FulfillmentError<'tcx>>>;
|
|
|
|
|
2018-06-27 20:04:32 +00:00
|
|
|
fn select_where_possible(
|
2018-03-11 02:29:22 +00:00
|
|
|
&mut self,
|
2018-06-27 20:04:32 +00:00
|
|
|
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
|
2018-03-11 02:29:22 +00:00
|
|
|
) -> Result<(), Vec<FulfillmentError<'tcx>>>;
|
|
|
|
|
2018-04-19 05:13:20 +00:00
|
|
|
fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>>;
|
2018-03-11 02:29:22 +00:00
|
|
|
}
|
|
|
|
|
2018-06-27 20:04:32 +00:00
|
|
|
pub trait TraitEngineExt<'tcx> {
|
|
|
|
fn register_predicate_obligations(
|
|
|
|
&mut self,
|
|
|
|
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
|
|
|
|
obligations: impl IntoIterator<Item = PredicateObligation<'tcx>>,
|
|
|
|
);
|
|
|
|
}
|
2018-03-11 14:01:01 +00:00
|
|
|
|
2018-06-27 20:04:32 +00:00
|
|
|
impl<T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
|
|
|
|
fn register_predicate_obligations(
|
2018-03-22 16:06:47 +00:00
|
|
|
&mut self,
|
2018-06-27 20:04:32 +00:00
|
|
|
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
|
|
|
|
obligations: impl IntoIterator<Item = PredicateObligation<'tcx>>,
|
|
|
|
) {
|
2018-03-22 16:06:47 +00:00
|
|
|
for obligation in obligations {
|
|
|
|
self.register_predicate_obligation(infcx, obligation);
|
|
|
|
}
|
|
|
|
}
|
2018-03-11 02:29:22 +00:00
|
|
|
}
|
2018-06-27 20:04:32 +00:00
|
|
|
|
|
|
|
impl dyn TraitEngine<'tcx> {
|
|
|
|
pub fn new(_tcx: TyCtxt<'_, '_, 'tcx>) -> Box<Self> {
|
|
|
|
Box::new(FulfillmentContext::new())
|
|
|
|
}
|
|
|
|
}
|