]> git.lizzy.rs Git - rust.git/blob - src/librustc/traits/structural_impls.rs
Rollup merge of #41249 - GuillaumeGomez:rustdoc-render, r=steveklabnik,frewsxcv
[rust.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::{Lift, TyCtxt};
14 use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
15
16 use std::fmt;
17 use std::rc::Rc;
18
19 // structural impls for the structs in traits
20
21 impl<'tcx, T: fmt::Debug> fmt::Debug for Normalized<'tcx, T> {
22     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23         write!(f, "Normalized({:?},{:?})",
24                self.value,
25                self.obligations)
26     }
27 }
28
29 impl<'tcx> fmt::Debug for traits::RegionObligation<'tcx> {
30     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
31         write!(f, "RegionObligation(sub_region={:?}, sup_type={:?})",
32                self.sub_region,
33                self.sup_type)
34     }
35 }
36 impl<'tcx, O: fmt::Debug> fmt::Debug for traits::Obligation<'tcx, O> {
37     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
38         write!(f, "Obligation(predicate={:?},depth={})",
39                self.predicate,
40                self.recursion_depth)
41     }
42 }
43
44 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::Vtable<'tcx, N> {
45     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
46         match *self {
47             super::VtableImpl(ref v) =>
48                 write!(f, "{:?}", v),
49
50             super::VtableDefaultImpl(ref t) =>
51                 write!(f, "{:?}", t),
52
53             super::VtableClosure(ref d) =>
54                 write!(f, "{:?}", d),
55
56             super::VtableFnPointer(ref d) =>
57                 write!(f, "VtableFnPointer({:?})", d),
58
59             super::VtableObject(ref d) =>
60                 write!(f, "{:?}", d),
61
62             super::VtableParam(ref n) =>
63                 write!(f, "VtableParam({:?})", n),
64
65             super::VtableBuiltin(ref d) =>
66                 write!(f, "{:?}", d)
67         }
68     }
69 }
70
71 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableImplData<'tcx, N> {
72     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
73         write!(f, "VtableImpl(impl_def_id={:?}, substs={:?}, nested={:?})",
74                self.impl_def_id,
75                self.substs,
76                self.nested)
77     }
78 }
79
80 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableClosureData<'tcx, N> {
81     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
82         write!(f, "VtableClosure(closure_def_id={:?}, substs={:?}, nested={:?})",
83                self.closure_def_id,
84                self.substs,
85                self.nested)
86     }
87 }
88
89 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableBuiltinData<N> {
90     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
91         write!(f, "VtableBuiltin(nested={:?})", self.nested)
92     }
93 }
94
95 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableDefaultImplData<N> {
96     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
97         write!(f, "VtableDefaultImplData(trait_def_id={:?}, nested={:?})",
98                self.trait_def_id,
99                self.nested)
100     }
101 }
102
103 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableObjectData<'tcx, N> {
104     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
105         write!(f, "VtableObject(upcast={:?}, vtable_base={}, nested={:?})",
106                self.upcast_trait_ref,
107                self.vtable_base,
108                self.nested)
109     }
110 }
111
112 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableFnPointerData<'tcx, N> {
113     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
114         write!(f, "VtableFnPointer(fn_ty={:?}, nested={:?})",
115                self.fn_ty,
116                self.nested)
117     }
118 }
119
120 impl<'tcx> fmt::Debug for traits::FulfillmentError<'tcx> {
121     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
122         write!(f, "FulfillmentError({:?},{:?})",
123                self.obligation,
124                self.code)
125     }
126 }
127
128 impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
129     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
130         match *self {
131             super::CodeSelectionError(ref e) => write!(f, "{:?}", e),
132             super::CodeProjectionError(ref e) => write!(f, "{:?}", e),
133             super::CodeSubtypeError(ref a, ref b) =>
134                 write!(f, "CodeSubtypeError({:?}, {:?})", a, b),
135             super::CodeAmbiguity => write!(f, "Ambiguity")
136         }
137     }
138 }
139
140 impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
141     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
142         write!(f, "MismatchedProjectionTypes({:?})", self.err)
143     }
144 }
145
146 ///////////////////////////////////////////////////////////////////////////
147 // Lift implementations
148
149 impl<'a, 'tcx> Lift<'tcx> for traits::SelectionError<'a> {
150     type Lifted = traits::SelectionError<'tcx>;
151     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
152         match *self {
153             super::Unimplemented => Some(super::Unimplemented),
154             super::OutputTypeParameterMismatch(a, b, ref err) => {
155                 tcx.lift(&(a, b)).and_then(|(a, b)| {
156                     tcx.lift(err).map(|err| {
157                         super::OutputTypeParameterMismatch(a, b, err)
158                     })
159                 })
160             }
161             super::TraitNotObjectSafe(def_id) => {
162                 Some(super::TraitNotObjectSafe(def_id))
163             }
164         }
165     }
166 }
167
168 impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
169     type Lifted = traits::ObligationCauseCode<'tcx>;
170     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
171         match *self {
172             super::ReturnNoExpression => Some(super::ReturnNoExpression),
173             super::MiscObligation => Some(super::MiscObligation),
174             super::SliceOrArrayElem => Some(super::SliceOrArrayElem),
175             super::TupleElem => Some(super::TupleElem),
176             super::ProjectionWf(proj) => tcx.lift(&proj).map(super::ProjectionWf),
177             super::ItemObligation(def_id) => Some(super::ItemObligation(def_id)),
178             super::ReferenceOutlivesReferent(ty) => {
179                 tcx.lift(&ty).map(super::ReferenceOutlivesReferent)
180             }
181             super::ObjectTypeBound(ty, r) => {
182                 tcx.lift(&ty).and_then(|ty| {
183                     tcx.lift(&r).and_then(|r| {
184                         Some(super::ObjectTypeBound(ty, r))
185                     })
186                 })
187             }
188             super::ObjectCastObligation(ty) => {
189                 tcx.lift(&ty).map(super::ObjectCastObligation)
190             }
191             super::AssignmentLhsSized => Some(super::AssignmentLhsSized),
192             super::StructInitializerSized => Some(super::StructInitializerSized),
193             super::VariableType(id) => Some(super::VariableType(id)),
194             super::ReturnType => Some(super::ReturnType),
195             super::RepeatVec => Some(super::RepeatVec),
196             super::FieldSized => Some(super::FieldSized),
197             super::ConstSized => Some(super::ConstSized),
198             super::SharedStatic => Some(super::SharedStatic),
199             super::BuiltinDerivedObligation(ref cause) => {
200                 tcx.lift(cause).map(super::BuiltinDerivedObligation)
201             }
202             super::ImplDerivedObligation(ref cause) => {
203                 tcx.lift(cause).map(super::ImplDerivedObligation)
204             }
205             super::CompareImplMethodObligation { item_name,
206                                                  impl_item_def_id,
207                                                  trait_item_def_id,
208                                                  lint_id } => {
209                 Some(super::CompareImplMethodObligation {
210                     item_name: item_name,
211                     impl_item_def_id: impl_item_def_id,
212                     trait_item_def_id: trait_item_def_id,
213                     lint_id: lint_id,
214                 })
215             }
216             super::ExprAssignable => {
217                 Some(super::ExprAssignable)
218             }
219             super::MatchExpressionArm { arm_span, source } => {
220                 Some(super::MatchExpressionArm { arm_span: arm_span,
221                                                  source: source })
222             }
223             super::IfExpression => {
224                 Some(super::IfExpression)
225             }
226             super::IfExpressionWithNoElse => {
227                 Some(super::IfExpressionWithNoElse)
228             }
229             super::EquatePredicate => {
230                 Some(super::EquatePredicate)
231             }
232             super::MainFunctionType => {
233                 Some(super::MainFunctionType)
234             }
235             super::StartFunctionType => {
236                 Some(super::StartFunctionType)
237             }
238             super::IntrinsicType => {
239                 Some(super::IntrinsicType)
240             }
241             super::MethodReceiver => {
242                 Some(super::MethodReceiver)
243             }
244         }
245     }
246 }
247
248 impl<'a, 'tcx> Lift<'tcx> for traits::DerivedObligationCause<'a> {
249     type Lifted = traits::DerivedObligationCause<'tcx>;
250     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
251         tcx.lift(&self.parent_trait_ref).and_then(|trait_ref| {
252             tcx.lift(&*self.parent_code).map(|code| {
253                 traits::DerivedObligationCause {
254                     parent_trait_ref: trait_ref,
255                     parent_code: Rc::new(code)
256                 }
257             })
258         })
259     }
260 }
261
262 impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCause<'a> {
263     type Lifted = traits::ObligationCause<'tcx>;
264     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
265         tcx.lift(&self.code).map(|code| {
266             traits::ObligationCause {
267                 span: self.span,
268                 body_id: self.body_id,
269                 code: code,
270             }
271         })
272     }
273 }
274
275 // For trans only.
276 impl<'a, 'tcx> Lift<'tcx> for traits::Vtable<'a, ()> {
277     type Lifted = traits::Vtable<'tcx, ()>;
278     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
279         match self.clone() {
280             traits::VtableImpl(traits::VtableImplData {
281                 impl_def_id,
282                 substs,
283                 nested
284             }) => {
285                 tcx.lift(&substs).map(|substs| {
286                     traits::VtableImpl(traits::VtableImplData {
287                         impl_def_id: impl_def_id,
288                         substs: substs,
289                         nested: nested
290                     })
291                 })
292             }
293             traits::VtableDefaultImpl(t) => Some(traits::VtableDefaultImpl(t)),
294             traits::VtableClosure(traits::VtableClosureData {
295                 closure_def_id,
296                 substs,
297                 nested
298             }) => {
299                 tcx.lift(&substs).map(|substs| {
300                     traits::VtableClosure(traits::VtableClosureData {
301                         closure_def_id: closure_def_id,
302                         substs: substs,
303                         nested: nested
304                     })
305                 })
306             }
307             traits::VtableFnPointer(traits::VtableFnPointerData { fn_ty, nested }) => {
308                 tcx.lift(&fn_ty).map(|fn_ty| {
309                     traits::VtableFnPointer(traits::VtableFnPointerData {
310                         fn_ty: fn_ty,
311                         nested: nested,
312                     })
313                 })
314             }
315             traits::VtableParam(n) => Some(traits::VtableParam(n)),
316             traits::VtableBuiltin(d) => Some(traits::VtableBuiltin(d)),
317             traits::VtableObject(traits::VtableObjectData {
318                 upcast_trait_ref,
319                 vtable_base,
320                 nested
321             }) => {
322                 tcx.lift(&upcast_trait_ref).map(|trait_ref| {
323                     traits::VtableObject(traits::VtableObjectData {
324                         upcast_trait_ref: trait_ref,
325                         vtable_base: vtable_base,
326                         nested: nested
327                     })
328                 })
329             }
330         }
331     }
332 }
333
334 ///////////////////////////////////////////////////////////////////////////
335 // TypeFoldable implementations.
336
337 impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O>
338 {
339     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
340         traits::Obligation {
341             cause: self.cause.clone(),
342             recursion_depth: self.recursion_depth,
343             predicate: self.predicate.fold_with(folder),
344         }
345     }
346
347     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
348         self.predicate.visit_with(visitor)
349     }
350 }
351
352 impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableImplData<'tcx, N> {
353     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
354         traits::VtableImplData {
355             impl_def_id: self.impl_def_id,
356             substs: self.substs.fold_with(folder),
357             nested: self.nested.fold_with(folder),
358         }
359     }
360
361     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
362         self.substs.visit_with(visitor) || self.nested.visit_with(visitor)
363     }
364 }
365
366 impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableClosureData<'tcx, N> {
367     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
368         traits::VtableClosureData {
369             closure_def_id: self.closure_def_id,
370             substs: self.substs.fold_with(folder),
371             nested: self.nested.fold_with(folder),
372         }
373     }
374
375     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
376         self.substs.visit_with(visitor) || self.nested.visit_with(visitor)
377     }
378 }
379
380 impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableDefaultImplData<N> {
381     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
382         traits::VtableDefaultImplData {
383             trait_def_id: self.trait_def_id,
384             nested: self.nested.fold_with(folder),
385         }
386     }
387
388     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
389         self.nested.visit_with(visitor)
390     }
391 }
392
393 impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableBuiltinData<N> {
394     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
395         traits::VtableBuiltinData {
396             nested: self.nested.fold_with(folder),
397         }
398     }
399
400     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
401         self.nested.visit_with(visitor)
402     }
403 }
404
405 impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableObjectData<'tcx, N> {
406     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
407         traits::VtableObjectData {
408             upcast_trait_ref: self.upcast_trait_ref.fold_with(folder),
409             vtable_base: self.vtable_base,
410             nested: self.nested.fold_with(folder),
411         }
412     }
413
414     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
415         self.upcast_trait_ref.visit_with(visitor) || self.nested.visit_with(visitor)
416     }
417 }
418
419 impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableFnPointerData<'tcx, N> {
420     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
421         traits::VtableFnPointerData {
422             fn_ty: self.fn_ty.fold_with(folder),
423             nested: self.nested.fold_with(folder),
424         }
425     }
426
427     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
428         self.fn_ty.visit_with(visitor) || self.nested.visit_with(visitor)
429     }
430 }
431
432 impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Vtable<'tcx, N> {
433     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
434         match *self {
435             traits::VtableImpl(ref v) => traits::VtableImpl(v.fold_with(folder)),
436             traits::VtableDefaultImpl(ref t) => traits::VtableDefaultImpl(t.fold_with(folder)),
437             traits::VtableClosure(ref d) => {
438                 traits::VtableClosure(d.fold_with(folder))
439             }
440             traits::VtableFnPointer(ref d) => {
441                 traits::VtableFnPointer(d.fold_with(folder))
442             }
443             traits::VtableParam(ref n) => traits::VtableParam(n.fold_with(folder)),
444             traits::VtableBuiltin(ref d) => traits::VtableBuiltin(d.fold_with(folder)),
445             traits::VtableObject(ref d) => traits::VtableObject(d.fold_with(folder)),
446         }
447     }
448
449     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
450         match *self {
451             traits::VtableImpl(ref v) => v.visit_with(visitor),
452             traits::VtableDefaultImpl(ref t) => t.visit_with(visitor),
453             traits::VtableClosure(ref d) => d.visit_with(visitor),
454             traits::VtableFnPointer(ref d) => d.visit_with(visitor),
455             traits::VtableParam(ref n) => n.visit_with(visitor),
456             traits::VtableBuiltin(ref d) => d.visit_with(visitor),
457             traits::VtableObject(ref d) => d.visit_with(visitor),
458         }
459     }
460 }
461
462 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Normalized<'tcx, T> {
463     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
464         Normalized {
465             value: self.value.fold_with(folder),
466             obligations: self.obligations.fold_with(folder),
467         }
468     }
469
470     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
471         self.value.visit_with(visitor) || self.obligations.visit_with(visitor)
472     }
473 }
474
475 impl<'tcx> TypeFoldable<'tcx> for traits::ObligationCauseCode<'tcx> {
476     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
477         match *self {
478             super::ExprAssignable |
479             super::MatchExpressionArm { arm_span: _, source: _ } |
480             super::IfExpression |
481             super::IfExpressionWithNoElse |
482             super::EquatePredicate |
483             super::MainFunctionType |
484             super::StartFunctionType |
485             super::IntrinsicType |
486             super::MethodReceiver |
487             super::MiscObligation |
488             super::SliceOrArrayElem |
489             super::TupleElem |
490             super::ItemObligation(_) |
491             super::AssignmentLhsSized |
492             super::StructInitializerSized |
493             super::VariableType(_) |
494             super::ReturnType |
495             super::ReturnNoExpression |
496             super::RepeatVec |
497             super::FieldSized |
498             super::ConstSized |
499             super::SharedStatic |
500             super::CompareImplMethodObligation { .. } => self.clone(),
501
502             super::ProjectionWf(proj) => super::ProjectionWf(proj.fold_with(folder)),
503             super::ReferenceOutlivesReferent(ty) => {
504                 super::ReferenceOutlivesReferent(ty.fold_with(folder))
505             }
506             super::ObjectTypeBound(ty, r) => {
507                 super::ObjectTypeBound(ty.fold_with(folder), r.fold_with(folder))
508             }
509             super::ObjectCastObligation(ty) => {
510                 super::ObjectCastObligation(ty.fold_with(folder))
511             }
512             super::BuiltinDerivedObligation(ref cause) => {
513                 super::BuiltinDerivedObligation(cause.fold_with(folder))
514             }
515             super::ImplDerivedObligation(ref cause) => {
516                 super::ImplDerivedObligation(cause.fold_with(folder))
517             }
518         }
519     }
520
521     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
522         match *self {
523             super::ExprAssignable |
524             super::MatchExpressionArm { arm_span: _, source: _ } |
525             super::IfExpression |
526             super::IfExpressionWithNoElse |
527             super::EquatePredicate |
528             super::MainFunctionType |
529             super::StartFunctionType |
530             super::IntrinsicType |
531             super::MethodReceiver |
532             super::MiscObligation |
533             super::SliceOrArrayElem |
534             super::TupleElem |
535             super::ItemObligation(_) |
536             super::AssignmentLhsSized |
537             super::StructInitializerSized |
538             super::VariableType(_) |
539             super::ReturnType |
540             super::ReturnNoExpression |
541             super::RepeatVec |
542             super::FieldSized |
543             super::ConstSized |
544             super::SharedStatic |
545             super::CompareImplMethodObligation { .. } => false,
546
547             super::ProjectionWf(proj) => proj.visit_with(visitor),
548             super::ReferenceOutlivesReferent(ty) => ty.visit_with(visitor),
549             super::ObjectTypeBound(ty, r) => ty.visit_with(visitor) || r.visit_with(visitor),
550             super::ObjectCastObligation(ty) => ty.visit_with(visitor),
551             super::BuiltinDerivedObligation(ref cause) => cause.visit_with(visitor),
552             super::ImplDerivedObligation(ref cause) => cause.visit_with(visitor)
553         }
554     }
555 }
556
557 impl<'tcx> TypeFoldable<'tcx> for traits::DerivedObligationCause<'tcx> {
558     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
559         traits::DerivedObligationCause {
560             parent_trait_ref: self.parent_trait_ref.fold_with(folder),
561             parent_code: self.parent_code.fold_with(folder)
562         }
563     }
564
565     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
566         self.parent_trait_ref.visit_with(visitor) || self.parent_code.visit_with(visitor)
567     }
568 }
569
570 impl<'tcx> TypeFoldable<'tcx> for traits::ObligationCause<'tcx> {
571     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
572         traits::ObligationCause {
573             span: self.span,
574             body_id: self.body_id,
575             code: self.code.fold_with(folder),
576         }
577     }
578
579     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
580         self.code.visit_with(visitor)
581     }
582 }