1 use crate::infer
::InferCtxt
;
2 use crate::traits
::Obligation
;
3 use rustc_hir
::def_id
::DefId
;
4 use rustc_middle
::ty
::{self, ToPredicate, Ty, WithConstness}
;
6 use super::FulfillmentError
;
7 use super::{ObligationCause, PredicateObligation}
;
9 pub trait TraitEngine
<'tcx
>: 'tcx
{
10 fn normalize_projection_type(
12 infcx
: &InferCtxt
<'_
, 'tcx
>,
13 param_env
: ty
::ParamEnv
<'tcx
>,
14 projection_ty
: ty
::ProjectionTy
<'tcx
>,
15 cause
: ObligationCause
<'tcx
>,
18 /// Requires that `ty` must implement the trait with `def_id` in
19 /// the given environment. This trait must not have any type
20 /// parameters (except for `Self`).
23 infcx
: &InferCtxt
<'_
, 'tcx
>,
24 param_env
: ty
::ParamEnv
<'tcx
>,
27 cause
: ObligationCause
<'tcx
>,
29 let trait_ref
= ty
::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) }
;
30 self.register_predicate_obligation(
36 predicate
: trait_ref
.without_const().to_predicate(),
41 fn register_predicate_obligation(
43 infcx
: &InferCtxt
<'_
, 'tcx
>,
44 obligation
: PredicateObligation
<'tcx
>,
47 fn select_all_or_error(
49 infcx
: &InferCtxt
<'_
, 'tcx
>,
50 ) -> Result
<(), Vec
<FulfillmentError
<'tcx
>>>;
52 fn select_where_possible(
54 infcx
: &InferCtxt
<'_
, 'tcx
>,
55 ) -> Result
<(), Vec
<FulfillmentError
<'tcx
>>>;
57 fn pending_obligations(&self) -> Vec
<PredicateObligation
<'tcx
>>;
60 pub trait TraitEngineExt
<'tcx
> {
61 fn register_predicate_obligations(
63 infcx
: &InferCtxt
<'_
, 'tcx
>,
64 obligations
: impl IntoIterator
<Item
= PredicateObligation
<'tcx
>>,
68 impl<T
: ?Sized
+ TraitEngine
<'tcx
>> TraitEngineExt
<'tcx
> for T
{
69 fn register_predicate_obligations(
71 infcx
: &InferCtxt
<'_
, 'tcx
>,
72 obligations
: impl IntoIterator
<Item
= PredicateObligation
<'tcx
>>,
74 for obligation
in obligations
{
75 self.register_predicate_obligation(infcx
, obligation
);