]>
Commit | Line | Data |
---|---|---|
74b04a01 XL |
1 | use crate::traits; |
2 | use crate::traits::project::Normalized; | |
064997fb FG |
3 | use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable}; |
4 | use rustc_middle::ty::visit::{TypeVisitable, TypeVisitor}; | |
9ffffee4 | 5 | use rustc_middle::ty::{self, TyCtxt}; |
74b04a01 XL |
6 | |
7 | use std::fmt; | |
29967ef6 | 8 | use std::ops::ControlFlow; |
74b04a01 XL |
9 | |
10 | // Structural impls for the structs in `traits`. | |
11 | ||
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) | |
15 | } | |
16 | } | |
17 | ||
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()) { | |
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 | ||
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) | |
35 | } | |
36 | } | |
37 | ||
38 | impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> { | |
39 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
40 | match *self { | |
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) | |
45 | } | |
f9f354fc XL |
46 | super::CodeConstEquateError(ref a, ref b) => { |
47 | write!(f, "CodeConstEquateError({:?}, {:?})", a, b) | |
48 | } | |
74b04a01 | 49 | super::CodeAmbiguity => write!(f, "Ambiguity"), |
2b03887a | 50 | super::CodeCycle(ref cycle) => write!(f, "Cycle({:?})", cycle), |
74b04a01 XL |
51 | } |
52 | } | |
53 | } | |
54 | ||
55 | impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> { | |
56 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
57 | write!(f, "MismatchedProjectionTypes({:?})", self.err) | |
58 | } | |
59 | } | |
60 | ||
61 | /////////////////////////////////////////////////////////////////////////// | |
62 | // TypeFoldable implementations. | |
63 | ||
9ffffee4 FG |
64 | impl<'tcx, O: TypeFoldable<TyCtxt<'tcx>>> TypeFoldable<TyCtxt<'tcx>> |
65 | for traits::Obligation<'tcx, O> | |
66 | { | |
67 | fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( | |
68 | self, | |
69 | folder: &mut F, | |
70 | ) -> Result<Self, F::Error> { | |
a2a8927a | 71 | Ok(traits::Obligation { |
fc512014 | 72 | cause: self.cause, |
74b04a01 | 73 | recursion_depth: self.recursion_depth, |
a2a8927a XL |
74 | predicate: self.predicate.try_fold_with(folder)?, |
75 | param_env: self.param_env.try_fold_with(folder)?, | |
76 | }) | |
74b04a01 | 77 | } |
064997fb | 78 | } |
74b04a01 | 79 | |
9ffffee4 FG |
80 | impl<'tcx, O: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>> |
81 | for traits::Obligation<'tcx, O> | |
82 | { | |
83 | fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> { | |
3c0e092e XL |
84 | self.predicate.visit_with(visitor)?; |
85 | self.param_env.visit_with(visitor) | |
74b04a01 XL |
86 | } |
87 | } |