use std::fmt::Debug;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::{self, Ty, Upcast};
use super::{ObligationCause, PredicateObligation};
use crate::infer::InferCtxt;
use crate::traits::Obligation;
#[derive(Clone, Debug)]
pub enum ScrubbedTraitError<'tcx> {
TrueError,
Ambiguity,
Cycle(Vec<PredicateObligation<'tcx>>),
}
impl<'tcx> ScrubbedTraitError<'tcx> {
pub fn is_true_error(&self) -> bool {
match self {
ScrubbedTraitError::TrueError => true,
ScrubbedTraitError::Ambiguity | ScrubbedTraitError::Cycle(_) => false,
}
}
}
pub trait TraitEngine<'tcx, E: 'tcx>: 'tcx {
fn register_bound(
&mut self,
infcx: &InferCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
ty: Ty<'tcx>,
def_id: DefId,
cause: ObligationCause<'tcx>,
) {
let trait_ref = ty::TraitRef::new(infcx.tcx, def_id, [ty]);
self.register_predicate_obligation(
infcx,
Obligation {
cause,
recursion_depth: 0,
param_env,
predicate: trait_ref.upcast(infcx.tcx),
},
);
}
fn register_predicate_obligation(
&mut self,
infcx: &InferCtxt<'tcx>,
obligation: PredicateObligation<'tcx>,
);
fn register_predicate_obligations(
&mut self,
infcx: &InferCtxt<'tcx>,
obligations: Vec<PredicateObligation<'tcx>>,
) {
for obligation in obligations {
self.register_predicate_obligation(infcx, obligation);
}
}
#[must_use]
fn select_where_possible(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<E>;
fn collect_remaining_errors(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<E>;
#[must_use]
fn select_all_or_error(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<E> {
let errors = self.select_where_possible(infcx);
if !errors.is_empty() {
return errors;
}
self.collect_remaining_errors(infcx)
}
fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>>;
fn drain_unstalled_obligations(
&mut self,
infcx: &InferCtxt<'tcx>,
) -> Vec<PredicateObligation<'tcx>>;
}
pub trait FromSolverError<'tcx, E>: Debug + 'tcx {
fn from_solver_error(infcx: &InferCtxt<'tcx>, error: E) -> Self;
}