rustc_infer/traits/
engine.rs1use std::fmt::Debug;
2
3use rustc_hir::def_id::DefId;
4use rustc_middle::ty::{self, Ty, Upcast};
5
6use super::{ObligationCause, PredicateObligation, PredicateObligations};
7use crate::infer::InferCtxt;
8use crate::traits::Obligation;
9
10#[derive(Clone, Debug)]
17pub enum ScrubbedTraitError<'tcx> {
18 TrueError,
20 Ambiguity,
22 Cycle(PredicateObligations<'tcx>),
25}
26
27impl<'tcx> ScrubbedTraitError<'tcx> {
28 pub fn is_true_error(&self) -> bool {
29 match self {
30 ScrubbedTraitError::TrueError => true,
31 ScrubbedTraitError::Ambiguity | ScrubbedTraitError::Cycle(_) => false,
32 }
33 }
34}
35
36pub trait TraitEngine<'tcx, E: 'tcx>: 'tcx {
37 fn register_bound(
41 &mut self,
42 infcx: &InferCtxt<'tcx>,
43 param_env: ty::ParamEnv<'tcx>,
44 ty: Ty<'tcx>,
45 def_id: DefId,
46 cause: ObligationCause<'tcx>,
47 ) {
48 let trait_ref = ty::TraitRef::new(infcx.tcx, def_id, [ty]);
49 self.register_predicate_obligation(
50 infcx,
51 Obligation {
52 cause,
53 recursion_depth: 0,
54 param_env,
55 predicate: trait_ref.upcast(infcx.tcx),
56 },
57 );
58 }
59
60 fn register_predicate_obligation(
61 &mut self,
62 infcx: &InferCtxt<'tcx>,
63 obligation: PredicateObligation<'tcx>,
64 );
65
66 fn register_predicate_obligations(
67 &mut self,
68 infcx: &InferCtxt<'tcx>,
69 obligations: PredicateObligations<'tcx>,
70 ) {
71 for obligation in obligations {
72 self.register_predicate_obligation(infcx, obligation);
73 }
74 }
75
76 #[must_use]
77 fn select_where_possible(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<E>;
78
79 fn collect_remaining_errors(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<E>;
80
81 #[must_use]
82 fn select_all_or_error(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<E> {
83 let errors = self.select_where_possible(infcx);
84 if !errors.is_empty() {
85 return errors;
86 }
87
88 self.collect_remaining_errors(infcx)
89 }
90
91 fn has_pending_obligations(&self) -> bool;
92
93 fn pending_obligations(&self) -> PredicateObligations<'tcx>;
94
95 fn drain_stalled_obligations_for_coroutines(
99 &mut self,
100 infcx: &InferCtxt<'tcx>,
101 ) -> PredicateObligations<'tcx>;
102}
103
104pub trait FromSolverError<'tcx, E>: Debug + 'tcx {
105 fn from_solver_error(infcx: &InferCtxt<'tcx>, error: E) -> Self;
106}