1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 use ty
::{self, Ty, TyCtxt}
;
13 use hir
::def_id
::DefId
;
15 use super::{FulfillmentContext, FulfillmentError}
;
16 use super::{ObligationCause, PendingPredicateObligation, PredicateObligation}
;
18 pub trait TraitEngine
<'tcx
>: 'tcx
{
19 fn normalize_projection_type
<'a
, 'gcx
>(
21 infcx
: &InferCtxt
<'a
, 'gcx
, 'tcx
>,
22 param_env
: ty
::ParamEnv
<'tcx
>,
23 projection_ty
: ty
::ProjectionTy
<'tcx
>,
24 cause
: ObligationCause
<'tcx
>,
27 fn register_bound
<'a
, 'gcx
>(
29 infcx
: &InferCtxt
<'a
, 'gcx
, 'tcx
>,
30 param_env
: ty
::ParamEnv
<'tcx
>,
33 cause
: ObligationCause
<'tcx
>,
36 fn register_predicate_obligation
<'a
, 'gcx
>(
38 infcx
: &InferCtxt
<'a
, 'gcx
, 'tcx
>,
39 obligation
: PredicateObligation
<'tcx
>,
42 fn select_all_or_error
<'a
, 'gcx
>(
44 infcx
: &InferCtxt
<'a
, 'gcx
, 'tcx
>,
45 ) -> Result
<(), Vec
<FulfillmentError
<'tcx
>>>;
47 fn select_where_possible
<'a
, 'gcx
>(
49 infcx
: &InferCtxt
<'a
, 'gcx
, 'tcx
>,
50 ) -> Result
<(), Vec
<FulfillmentError
<'tcx
>>>;
52 fn pending_obligations(&self) -> Vec
<PendingPredicateObligation
<'tcx
>>;
55 impl<'a
, 'gcx
, 'tcx
> dyn TraitEngine
<'tcx
> {
56 pub fn new(_tcx
: TyCtxt
<'_
, '_
, 'tcx
>) -> Box
<Self> {
57 Box
::new(FulfillmentContext
::new())
60 pub fn register_predicate_obligations
<I
>(
62 infcx
: &InferCtxt
<'a
, 'gcx
, 'tcx
>,
65 I
: IntoIterator
<Item
= PredicateObligation
<'tcx
>>,
67 for obligation
in obligations
{
68 self.register_predicate_obligation(infcx
, obligation
);