]> git.proxmox.com Git - rustc.git/blob - src/librustc_infer/traits/structural_impls.rs
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_infer / traits / structural_impls.rs
1 use crate::traits;
2 use crate::traits::project::Normalized;
3 use rustc_middle::ty;
4 use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
5
6 use std::fmt;
7
8 // Structural impls for the structs in `traits`.
9
10 impl<'tcx, T: fmt::Debug> fmt::Debug for Normalized<'tcx, T> {
11 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12 write!(f, "Normalized({:?}, {:?})", self.value, self.obligations)
13 }
14 }
15
16 impl<'tcx, O: fmt::Debug> fmt::Debug for traits::Obligation<'tcx, O> {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 if ty::tls::with(|tcx| tcx.sess.verbose()) {
19 write!(
20 f,
21 "Obligation(predicate={:?}, cause={:?}, param_env={:?}, depth={})",
22 self.predicate, self.cause, self.param_env, self.recursion_depth
23 )
24 } else {
25 write!(f, "Obligation(predicate={:?}, depth={})", self.predicate, self.recursion_depth)
26 }
27 }
28 }
29
30 impl<'tcx> fmt::Debug for traits::FulfillmentError<'tcx> {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 write!(f, "FulfillmentError({:?},{:?})", self.obligation, self.code)
33 }
34 }
35
36 impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 match *self {
39 super::CodeSelectionError(ref e) => write!(f, "{:?}", e),
40 super::CodeProjectionError(ref e) => write!(f, "{:?}", e),
41 super::CodeSubtypeError(ref a, ref b) => {
42 write!(f, "CodeSubtypeError({:?}, {:?})", a, b)
43 }
44 super::CodeConstEquateError(ref a, ref b) => {
45 write!(f, "CodeConstEquateError({:?}, {:?})", a, b)
46 }
47 super::CodeAmbiguity => write!(f, "Ambiguity"),
48 }
49 }
50 }
51
52 impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
53 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54 write!(f, "MismatchedProjectionTypes({:?})", self.err)
55 }
56 }
57
58 ///////////////////////////////////////////////////////////////////////////
59 // TypeFoldable implementations.
60
61 impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O> {
62 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
63 traits::Obligation {
64 cause: self.cause.clone(),
65 recursion_depth: self.recursion_depth,
66 predicate: self.predicate.fold_with(folder),
67 param_env: self.param_env.fold_with(folder),
68 }
69 }
70
71 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
72 self.predicate.visit_with(visitor)
73 }
74 }