rust/src/librustc/traits/engine.rs

70 lines
1.9 KiB
Rust
Raw Normal View History

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};
use super::{ObligationCause, PredicateObligation};
2018-03-11 02:29:22 +00:00
pub trait TraitEngine<'tcx>: 'tcx {
fn normalize_projection_type(
2018-03-11 02:29:22 +00:00
&mut self,
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>;
fn register_bound(
2018-03-11 02:29:22 +00:00
&mut self,
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>,
);
fn register_predicate_obligation(
2018-03-11 02:29:22 +00:00
&mut self,
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
2018-03-11 02:29:22 +00:00
obligation: PredicateObligation<'tcx>,
);
fn select_all_or_error(
2018-03-11 02:29:22 +00:00
&mut self,
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
2018-03-11 02:29:22 +00:00
) -> Result<(), Vec<FulfillmentError<'tcx>>>;
fn select_where_possible(
2018-03-11 02:29:22 +00:00
&mut self,
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
2018-03-11 02:29:22 +00:00
) -> Result<(), Vec<FulfillmentError<'tcx>>>;
fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>>;
2018-03-11 02:29:22 +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
impl<T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
fn register_predicate_obligations(
2018-03-22 16:06:47 +00:00
&mut self,
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
}
impl dyn TraitEngine<'tcx> {
pub fn new(_tcx: TyCtxt<'_, '_, 'tcx>) -> Box<Self> {
Box::new(FulfillmentContext::new())
}
}