]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_infer/src/traits/structural_impls.rs
New upstream version 1.64.0+dfsg1
[rustc.git] / compiler / rustc_infer / src / traits / structural_impls.rs
CommitLineData
74b04a01
XL
1use crate::traits;
2use crate::traits::project::Normalized;
ba9703b0 3use rustc_middle::ty;
064997fb
FG
4use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable};
5use rustc_middle::ty::visit::{TypeVisitable, TypeVisitor};
74b04a01
XL
6
7use std::fmt;
29967ef6 8use std::ops::ControlFlow;
74b04a01
XL
9
10// Structural impls for the structs in `traits`.
11
12impl<'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()) {
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::FulfillmentError<'tcx> {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 write!(f, "FulfillmentError({:?},{:?})", self.obligation, self.code)
35 }
36}
37
38impl<'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
XL
49 super::CodeAmbiguity => write!(f, "Ambiguity"),
50 }
51 }
52}
53
54impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
55 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56 write!(f, "MismatchedProjectionTypes({:?})", self.err)
57 }
58}
59
60///////////////////////////////////////////////////////////////////////////
61// TypeFoldable implementations.
62
63impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O> {
923072b8 64 fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
a2a8927a 65 Ok(traits::Obligation {
fc512014 66 cause: self.cause,
74b04a01 67 recursion_depth: self.recursion_depth,
a2a8927a
XL
68 predicate: self.predicate.try_fold_with(folder)?,
69 param_env: self.param_env.try_fold_with(folder)?,
70 })
74b04a01 71 }
064997fb 72}
74b04a01 73
064997fb 74impl<'tcx, O: TypeVisitable<'tcx>> TypeVisitable<'tcx> for traits::Obligation<'tcx, O> {
923072b8 75 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
3c0e092e
XL
76 self.predicate.visit_with(visitor)?;
77 self.param_env.visit_with(visitor)
74b04a01
XL
78 }
79}