2019-02-05 11:20:45 -06:00
|
|
|
use crate::traits;
|
|
|
|
use crate::traits::project::Normalized;
|
2020-03-29 16:41:09 +02:00
|
|
|
use rustc_middle::ty;
|
|
|
|
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
2015-09-14 12:53:53 +03:00
|
|
|
|
|
|
|
use std::fmt;
|
2020-10-21 14:24:35 +02:00
|
|
|
use std::ops::ControlFlow;
|
2015-09-14 12:53:53 +03:00
|
|
|
|
2019-02-28 22:43:53 +00:00
|
|
|
// Structural impls for the structs in `traits`.
|
2015-09-14 12:53:53 +03:00
|
|
|
|
|
|
|
impl<'tcx, T: fmt::Debug> fmt::Debug for Normalized<'tcx, T> {
|
2018-08-29 22:02:42 -07:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2019-02-28 22:43:53 +00:00
|
|
|
write!(f, "Normalized({:?}, {:?})", self.value, self.obligations)
|
2015-09-14 12:53:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx, O: fmt::Debug> fmt::Debug for traits::Obligation<'tcx, O> {
|
2018-08-29 22:02:42 -07:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2017-11-23 23:03:47 +02:00
|
|
|
if ty::tls::with(|tcx| tcx.sess.verbose()) {
|
2018-05-08 18:15:48 -03:00
|
|
|
write!(
|
|
|
|
f,
|
2019-02-28 22:43:53 +00:00
|
|
|
"Obligation(predicate={:?}, cause={:?}, param_env={:?}, depth={})",
|
2018-12-03 00:49:12 +02:00
|
|
|
self.predicate, self.cause, self.param_env, self.recursion_depth
|
2018-05-08 18:15:48 -03:00
|
|
|
)
|
2017-11-23 23:03:47 +02:00
|
|
|
} else {
|
2019-12-22 17:42:04 -05:00
|
|
|
write!(f, "Obligation(predicate={:?}, depth={})", self.predicate, self.recursion_depth)
|
2017-11-23 23:03:47 +02:00
|
|
|
}
|
2015-09-14 12:53:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> fmt::Debug for traits::FulfillmentError<'tcx> {
|
2018-08-29 22:02:42 -07:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2018-05-08 18:15:48 -03:00
|
|
|
write!(f, "FulfillmentError({:?},{:?})", self.obligation, self.code)
|
2015-09-14 12:53:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
|
2018-08-29 22:02:42 -07:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2015-09-14 12:53:53 +03:00
|
|
|
match *self {
|
|
|
|
super::CodeSelectionError(ref e) => write!(f, "{:?}", e),
|
|
|
|
super::CodeProjectionError(ref e) => write!(f, "{:?}", e),
|
2018-05-08 18:15:48 -03:00
|
|
|
super::CodeSubtypeError(ref a, ref b) => {
|
|
|
|
write!(f, "CodeSubtypeError({:?}, {:?})", a, b)
|
|
|
|
}
|
2020-02-29 10:03:04 +13:00
|
|
|
super::CodeConstEquateError(ref a, ref b) => {
|
|
|
|
write!(f, "CodeConstEquateError({:?}, {:?})", a, b)
|
|
|
|
}
|
2018-05-08 18:15:48 -03:00
|
|
|
super::CodeAmbiguity => write!(f, "Ambiguity"),
|
2015-09-14 12:53:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
|
2018-08-29 22:02:42 -07:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2015-09-14 12:53:53 +03:00
|
|
|
write!(f, "MismatchedProjectionTypes({:?})", self.err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-01 14:39:03 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// TypeFoldable implementations.
|
|
|
|
|
|
|
|
impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O> {
|
2020-10-24 02:21:18 +02:00
|
|
|
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
2018-11-01 14:39:03 +01:00
|
|
|
traits::Obligation {
|
|
|
|
cause: self.cause.clone(),
|
|
|
|
recursion_depth: self.recursion_depth,
|
|
|
|
predicate: self.predicate.fold_with(folder),
|
|
|
|
param_env: self.param_env.fold_with(folder),
|
2018-03-28 14:13:08 +02:00
|
|
|
}
|
2018-11-01 14:39:03 +01:00
|
|
|
}
|
|
|
|
|
2020-10-25 11:50:56 +01:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
|
2018-11-01 14:39:03 +01:00
|
|
|
self.predicate.visit_with(visitor)
|
2018-03-28 14:13:08 +02:00
|
|
|
}
|
|
|
|
}
|