]> git.proxmox.com Git - rustc.git/blame - src/librustc/traits/engine.rs
New upstream version 1.27.2+dfsg1
[rustc.git] / src / librustc / traits / engine.rs
CommitLineData
0531ce1d
XL
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.
4//
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.
10
11use infer::InferCtxt;
12use ty::{self, Ty, TyCtxt};
13use hir::def_id::DefId;
14
15use super::{FulfillmentContext, FulfillmentError};
16use super::{ObligationCause, PendingPredicateObligation, PredicateObligation};
17
18pub trait TraitEngine<'tcx>: 'tcx {
19 fn normalize_projection_type<'a, 'gcx>(
20 &mut self,
21 infcx: &InferCtxt<'a, 'gcx, 'tcx>,
22 param_env: ty::ParamEnv<'tcx>,
23 projection_ty: ty::ProjectionTy<'tcx>,
24 cause: ObligationCause<'tcx>,
25 ) -> Ty<'tcx>;
26
27 fn register_bound<'a, 'gcx>(
28 &mut self,
29 infcx: &InferCtxt<'a, 'gcx, 'tcx>,
30 param_env: ty::ParamEnv<'tcx>,
31 ty: Ty<'tcx>,
32 def_id: DefId,
33 cause: ObligationCause<'tcx>,
34 );
35
36 fn register_predicate_obligation<'a, 'gcx>(
37 &mut self,
38 infcx: &InferCtxt<'a, 'gcx, 'tcx>,
39 obligation: PredicateObligation<'tcx>,
40 );
41
42 fn select_all_or_error<'a, 'gcx>(
43 &mut self,
44 infcx: &InferCtxt<'a, 'gcx, 'tcx>,
45 ) -> Result<(), Vec<FulfillmentError<'tcx>>>;
46
47 fn select_where_possible<'a, 'gcx>(
48 &mut self,
49 infcx: &InferCtxt<'a, 'gcx, 'tcx>,
50 ) -> Result<(), Vec<FulfillmentError<'tcx>>>;
51
52 fn pending_obligations(&self) -> Vec<PendingPredicateObligation<'tcx>>;
53}
54
55impl<'a, 'gcx, 'tcx> dyn TraitEngine<'tcx> {
56 pub fn new(_tcx: TyCtxt<'_, '_, 'tcx>) -> Box<Self> {
57 Box::new(FulfillmentContext::new())
58 }
59
60 pub fn register_predicate_obligations<I>(
61 &mut self,
62 infcx: &InferCtxt<'a, 'gcx, 'tcx>,
63 obligations: I,
64 ) where
65 I: IntoIterator<Item = PredicateObligation<'tcx>>,
66 {
67 for obligation in obligations {
68 self.register_predicate_obligation(infcx, obligation);
69 }
70 }
71}