rustc_infer/traits/
structural_impls.rs
1use std::fmt;
2
3use rustc_middle::ty::{
4 self, FallibleTypeFolder, TyCtxt, TypeFoldable, TypeVisitable, TypeVisitor, try_visit,
5};
6
7use crate::traits;
8use crate::traits::project::Normalized;
9
10impl<'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)
15 }
16}
17
18impl<'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_internals()) {
21 write!(
22 f,
23 "Obligation(predicate={:?}, cause={:?}, param_env={:?}, depth={})",
24 self.predicate, self.cause, self.param_env, self.recursion_depth
25 )
26 } else {
27 write!(f, "Obligation(predicate={:?}, depth={})", self.predicate, self.recursion_depth)
28 }
29 }
30}
31
32impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 write!(f, "MismatchedProjectionTypes({:?})", self.err)
35 }
36}
37
38impl<'tcx, O: TypeFoldable<TyCtxt<'tcx>>> TypeFoldable<TyCtxt<'tcx>>
42 for traits::Obligation<'tcx, O>
43{
44 fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
45 self,
46 folder: &mut F,
47 ) -> Result<Self, F::Error> {
48 Ok(traits::Obligation {
49 cause: self.cause,
50 recursion_depth: self.recursion_depth,
51 predicate: self.predicate.try_fold_with(folder)?,
52 param_env: self.param_env.try_fold_with(folder)?,
53 })
54 }
55}
56
57impl<'tcx, O: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>>
58 for traits::Obligation<'tcx, O>
59{
60 fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
61 try_visit!(self.predicate.visit_with(visitor));
62 self.param_env.visit_with(visitor)
63 }
64}