2 use crate::traits::project::Normalized;
4 use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable};
5 use rustc_middle::ty::visit::{TypeVisitable, TypeVisitor};
8 use std::ops::ControlFlow;
10 // Structural impls for the structs in `traits`.
12 impl<'tcx, T: fmt::Debug> fmt::Debug for Normalized<'tcx, T> {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 write!(f, "Normalized({:?}, {:?})", self.value, self.obligations)
18 impl<'tcx, O: fmt::Debug> fmt::Debug for traits::Obligation<'tcx, O> {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 if ty::tls::with(|tcx| tcx.sess.verbose()) {
23 "Obligation(predicate={:?}, cause={:?}, param_env={:?}, depth={})",
24 self.predicate, self.cause, self.param_env, self.recursion_depth
27 write!(f, "Obligation(predicate={:?}, depth={})", self.predicate, self.recursion_depth)
32 impl<'tcx> fmt::Debug for traits::FulfillmentError<'tcx> {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 write!(f, "FulfillmentError({:?},{:?})", self.obligation, self.code)
38 impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 super::CodeSelectionError(ref e) => write!(f, "{:?}", e),
42 super::CodeProjectionError(ref e) => write!(f, "{:?}", e),
43 super::CodeSubtypeError(ref a, ref b) => {
44 write!(f, "CodeSubtypeError({:?}, {:?})", a, b)
46 super::CodeConstEquateError(ref a, ref b) => {
47 write!(f, "CodeConstEquateError({:?}, {:?})", a, b)
49 super::CodeAmbiguity => write!(f, "Ambiguity"),
54 impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
55 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56 write!(f, "MismatchedProjectionTypes({:?})", self.err)
60 ///////////////////////////////////////////////////////////////////////////
61 // TypeFoldable implementations.
63 impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O> {
64 fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
65 Ok(traits::Obligation {
67 recursion_depth: self.recursion_depth,
68 predicate: self.predicate.try_fold_with(folder)?,
69 param_env: self.param_env.try_fold_with(folder)?,
74 impl<'tcx, O: TypeVisitable<'tcx>> TypeVisitable<'tcx> for traits::Obligation<'tcx, O> {
75 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
76 self.predicate.visit_with(visitor)?;
77 self.param_env.visit_with(visitor)