]> git.lizzy.rs Git - rust.git/blob - src/librustc/traits/engine.rs
Remove Ty prefix from Ty{Adt|Array|Slice|RawPtr|Ref|FnDef|FnPtr|Dynamic|Closure|Gener...
[rust.git] / src / librustc / traits / engine.rs
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
11 use infer::InferCtxt;
12 use ty::{self, Ty, TyCtxt};
13 use hir::def_id::DefId;
14
15 use super::{FulfillmentContext, FulfillmentError};
16 use super::{ObligationCause, PredicateObligation};
17
18 pub trait TraitEngine<'tcx>: 'tcx {
19     fn normalize_projection_type(
20         &mut self,
21         infcx: &InferCtxt<'_, '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(
28         &mut self,
29         infcx: &InferCtxt<'_, '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(
37         &mut self,
38         infcx: &InferCtxt<'_, 'gcx, 'tcx>,
39         obligation: PredicateObligation<'tcx>,
40     );
41
42     fn select_all_or_error(
43         &mut self,
44         infcx: &InferCtxt<'_, 'gcx, 'tcx>,
45     ) -> Result<(), Vec<FulfillmentError<'tcx>>>;
46
47     fn select_where_possible(
48         &mut self,
49         infcx: &InferCtxt<'_, 'gcx, 'tcx>,
50     ) -> Result<(), Vec<FulfillmentError<'tcx>>>;
51
52     fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>>;
53 }
54
55 pub trait TraitEngineExt<'tcx> {
56     fn register_predicate_obligations(
57         &mut self,
58         infcx: &InferCtxt<'_, 'gcx, 'tcx>,
59         obligations: impl IntoIterator<Item = PredicateObligation<'tcx>>,
60     );
61 }
62
63 impl<T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
64     fn register_predicate_obligations(
65         &mut self,
66         infcx: &InferCtxt<'_, 'gcx, 'tcx>,
67         obligations: impl IntoIterator<Item = PredicateObligation<'tcx>>,
68     ) {
69         for obligation in obligations {
70             self.register_predicate_obligation(infcx, obligation);
71         }
72     }
73 }
74
75 impl dyn TraitEngine<'tcx> {
76     pub fn new(_tcx: TyCtxt<'_, '_, 'tcx>) -> Box<Self> {
77         Box::new(FulfillmentContext::new())
78     }
79 }