]> git.proxmox.com Git - rustc.git/blob - src/librustc/traits/structural_impls.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / librustc / traits / structural_impls.rs
1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use traits;
12 use traits::project::Normalized;
13 use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
14
15 use std::fmt;
16
17 // structural impls for the structs in traits
18
19 impl<'tcx, T: fmt::Debug> fmt::Debug for Normalized<'tcx, T> {
20 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21 write!(f, "Normalized({:?},{:?})",
22 self.value,
23 self.obligations)
24 }
25 }
26
27 impl<'tcx> fmt::Debug for traits::RegionObligation<'tcx> {
28 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29 write!(f, "RegionObligation(sub_region={:?}, sup_type={:?})",
30 self.sub_region,
31 self.sup_type)
32 }
33 }
34 impl<'tcx, O: fmt::Debug> fmt::Debug for traits::Obligation<'tcx, O> {
35 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36 write!(f, "Obligation(predicate={:?},depth={})",
37 self.predicate,
38 self.recursion_depth)
39 }
40 }
41
42 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::Vtable<'tcx, N> {
43 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
44 match *self {
45 super::VtableImpl(ref v) =>
46 write!(f, "{:?}", v),
47
48 super::VtableDefaultImpl(ref t) =>
49 write!(f, "{:?}", t),
50
51 super::VtableClosure(ref d) =>
52 write!(f, "{:?}", d),
53
54 super::VtableFnPointer(ref d) =>
55 write!(f, "VtableFnPointer({:?})", d),
56
57 super::VtableObject(ref d) =>
58 write!(f, "{:?}", d),
59
60 super::VtableParam(ref n) =>
61 write!(f, "VtableParam({:?})", n),
62
63 super::VtableBuiltin(ref d) =>
64 write!(f, "{:?}", d)
65 }
66 }
67 }
68
69 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableImplData<'tcx, N> {
70 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
71 write!(f, "VtableImpl(impl_def_id={:?}, substs={:?}, nested={:?})",
72 self.impl_def_id,
73 self.substs,
74 self.nested)
75 }
76 }
77
78 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableClosureData<'tcx, N> {
79 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
80 write!(f, "VtableClosure(closure_def_id={:?}, substs={:?}, nested={:?})",
81 self.closure_def_id,
82 self.substs,
83 self.nested)
84 }
85 }
86
87 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableBuiltinData<N> {
88 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
89 write!(f, "VtableBuiltin(nested={:?})", self.nested)
90 }
91 }
92
93 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableDefaultImplData<N> {
94 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
95 write!(f, "VtableDefaultImplData(trait_def_id={:?}, nested={:?})",
96 self.trait_def_id,
97 self.nested)
98 }
99 }
100
101 impl<'tcx> fmt::Debug for traits::VtableObjectData<'tcx> {
102 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
103 write!(f, "VtableObject(upcast={:?}, vtable_base={})",
104 self.upcast_trait_ref,
105 self.vtable_base)
106 }
107 }
108
109 impl<'tcx> fmt::Debug for traits::FulfillmentError<'tcx> {
110 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
111 write!(f, "FulfillmentError({:?},{:?})",
112 self.obligation,
113 self.code)
114 }
115 }
116
117 impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
118 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
119 match *self {
120 super::CodeSelectionError(ref e) => write!(f, "{:?}", e),
121 super::CodeProjectionError(ref e) => write!(f, "{:?}", e),
122 super::CodeAmbiguity => write!(f, "Ambiguity")
123 }
124 }
125 }
126
127 impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
128 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
129 write!(f, "MismatchedProjectionTypes({:?})", self.err)
130 }
131 }
132
133 impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O>
134 {
135 fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
136 traits::Obligation {
137 cause: self.cause.clone(),
138 recursion_depth: self.recursion_depth,
139 predicate: self.predicate.fold_with(folder),
140 }
141 }
142
143 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
144 self.predicate.visit_with(visitor)
145 }
146 }
147
148 impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableImplData<'tcx, N> {
149 fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
150 let substs = self.substs.fold_with(folder);
151 traits::VtableImplData {
152 impl_def_id: self.impl_def_id,
153 substs: folder.tcx().mk_substs(substs),
154 nested: self.nested.fold_with(folder),
155 }
156 }
157
158 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
159 self.substs.visit_with(visitor) || self.nested.visit_with(visitor)
160 }
161 }
162
163 impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableClosureData<'tcx, N> {
164 fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
165 traits::VtableClosureData {
166 closure_def_id: self.closure_def_id,
167 substs: self.substs.fold_with(folder),
168 nested: self.nested.fold_with(folder),
169 }
170 }
171
172 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
173 self.substs.visit_with(visitor) || self.nested.visit_with(visitor)
174 }
175 }
176
177 impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableDefaultImplData<N> {
178 fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
179 traits::VtableDefaultImplData {
180 trait_def_id: self.trait_def_id,
181 nested: self.nested.fold_with(folder),
182 }
183 }
184
185 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
186 self.nested.visit_with(visitor)
187 }
188 }
189
190 impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableBuiltinData<N> {
191 fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
192 traits::VtableBuiltinData {
193 nested: self.nested.fold_with(folder),
194 }
195 }
196
197 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
198 self.nested.visit_with(visitor)
199 }
200 }
201
202 impl<'tcx> TypeFoldable<'tcx> for traits::VtableObjectData<'tcx> {
203 fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
204 traits::VtableObjectData {
205 upcast_trait_ref: self.upcast_trait_ref.fold_with(folder),
206 vtable_base: self.vtable_base
207 }
208 }
209
210 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
211 self.upcast_trait_ref.visit_with(visitor)
212 }
213 }
214
215 impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Vtable<'tcx, N> {
216 fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
217 match *self {
218 traits::VtableImpl(ref v) => traits::VtableImpl(v.fold_with(folder)),
219 traits::VtableDefaultImpl(ref t) => traits::VtableDefaultImpl(t.fold_with(folder)),
220 traits::VtableClosure(ref d) => {
221 traits::VtableClosure(d.fold_with(folder))
222 }
223 traits::VtableFnPointer(ref d) => {
224 traits::VtableFnPointer(d.fold_with(folder))
225 }
226 traits::VtableParam(ref n) => traits::VtableParam(n.fold_with(folder)),
227 traits::VtableBuiltin(ref d) => traits::VtableBuiltin(d.fold_with(folder)),
228 traits::VtableObject(ref d) => traits::VtableObject(d.fold_with(folder)),
229 }
230 }
231
232 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
233 match *self {
234 traits::VtableImpl(ref v) => v.visit_with(visitor),
235 traits::VtableDefaultImpl(ref t) => t.visit_with(visitor),
236 traits::VtableClosure(ref d) => d.visit_with(visitor),
237 traits::VtableFnPointer(ref d) => d.visit_with(visitor),
238 traits::VtableParam(ref n) => n.visit_with(visitor),
239 traits::VtableBuiltin(ref d) => d.visit_with(visitor),
240 traits::VtableObject(ref d) => d.visit_with(visitor),
241 }
242 }
243 }
244
245 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Normalized<'tcx, T> {
246 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
247 Normalized {
248 value: self.value.fold_with(folder),
249 obligations: self.obligations.fold_with(folder),
250 }
251 }
252
253 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
254 self.value.visit_with(visitor) || self.obligations.visit_with(visitor)
255 }
256 }