2 use crate::traits::project::Normalized;
4 use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeVisitor};
7 use std::ops::ControlFlow;
9 // Structural impls for the structs in `traits`.
11 impl<'tcx, T: fmt::Debug> fmt::Debug for Normalized<'tcx, T> {
12 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13 write!(f, "Normalized({:?}, {:?})", self.value, self.obligations)
17 impl<'tcx, O: fmt::Debug> fmt::Debug for traits::Obligation<'tcx, O> {
18 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19 if ty::tls::with(|tcx| tcx.sess.verbose()) {
22 "Obligation(predicate={:?}, cause={:?}, param_env={:?}, depth={})",
23 self.predicate, self.cause, self.param_env, self.recursion_depth
26 write!(f, "Obligation(predicate={:?}, depth={})", self.predicate, self.recursion_depth)
31 impl<'tcx> fmt::Debug for traits::FulfillmentError<'tcx> {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 write!(f, "FulfillmentError({:?},{:?})", self.obligation, self.code)
37 impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 super::CodeSelectionError(ref e) => write!(f, "{:?}", e),
41 super::CodeProjectionError(ref e) => write!(f, "{:?}", e),
42 super::CodeSubtypeError(ref a, ref b) => {
43 write!(f, "CodeSubtypeError({:?}, {:?})", a, b)
45 super::CodeConstEquateError(ref a, ref b) => {
46 write!(f, "CodeConstEquateError({:?}, {:?})", a, b)
48 super::CodeAmbiguity => write!(f, "Ambiguity"),
53 impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
54 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55 write!(f, "MismatchedProjectionTypes({:?})", self.err)
59 ///////////////////////////////////////////////////////////////////////////
60 // TypeFoldable implementations.
62 impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O> {
63 fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
64 Ok(traits::Obligation {
66 recursion_depth: self.recursion_depth,
67 predicate: self.predicate.try_fold_with(folder)?,
68 param_env: self.param_env.try_fold_with(folder)?,
72 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
73 self.predicate.visit_with(visitor)?;
74 self.param_env.visit_with(visitor)