]> git.proxmox.com Git - rustc.git/blame - src/librustc/ty/structural_impls.rs
New upstream version 1.14.0+dfsg1
[rustc.git] / src / librustc / ty / structural_impls.rs
CommitLineData
e9174d1e
SL
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
a7813a04 11use infer::type_variable;
9e0c209e 12use ty::{self, Lift, Ty, TyCtxt};
54a0048b 13use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
c30ab7b3 14use rustc_data_structures::accumulate_vec::AccumulateVec;
e9174d1e
SL
15
16use std::rc::Rc;
17use syntax::abi;
e9174d1e 18
54a0048b 19use hir;
e9174d1e 20
e9174d1e
SL
21///////////////////////////////////////////////////////////////////////////
22// Lift implementations
23
24impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>> Lift<'tcx> for (A, B) {
25 type Lifted = (A::Lifted, B::Lifted);
a7813a04 26 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
e9174d1e
SL
27 tcx.lift(&self.0).and_then(|a| tcx.lift(&self.1).map(|b| (a, b)))
28 }
29}
30
a7813a04
XL
31impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
32 type Lifted = Option<T::Lifted>;
33 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
34 match *self {
35 Some(ref x) => tcx.lift(x).map(Some),
36 None => Some(None)
37 }
38 }
39}
40
41impl<'tcx, T: Lift<'tcx>, E: Lift<'tcx>> Lift<'tcx> for Result<T, E> {
42 type Lifted = Result<T::Lifted, E::Lifted>;
43 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
44 match *self {
45 Ok(ref x) => tcx.lift(x).map(Ok),
46 Err(ref e) => tcx.lift(e).map(Err)
47 }
48 }
49}
50
e9174d1e
SL
51impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for [T] {
52 type Lifted = Vec<T::Lifted>;
a7813a04 53 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
b039eaaf
SL
54 // type annotation needed to inform `projection_must_outlive`
55 let mut result : Vec<<T as Lift<'tcx>>::Lifted>
56 = Vec::with_capacity(self.len());
e9174d1e
SL
57 for x in self {
58 if let Some(value) = tcx.lift(x) {
59 result.push(value);
60 } else {
61 return None;
62 }
63 }
64 Some(result)
65 }
66}
67
a7813a04
XL
68impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Vec<T> {
69 type Lifted = Vec<T::Lifted>;
70 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
71 tcx.lift(&self[..])
72 }
73}
74
9e0c209e
SL
75impl<'a, 'tcx> Lift<'tcx> for ty::TraitRef<'a> {
76 type Lifted = ty::TraitRef<'tcx>;
77 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
78 tcx.lift(&self.substs).map(|substs| ty::TraitRef {
79 def_id: self.def_id,
80 substs: substs
81 })
e9174d1e
SL
82 }
83}
84
9e0c209e
SL
85impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialTraitRef<'a> {
86 type Lifted = ty::ExistentialTraitRef<'tcx>;
87 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
88 tcx.lift(&self.substs).map(|substs| ty::ExistentialTraitRef {
e9174d1e
SL
89 def_id: self.def_id,
90 substs: substs
91 })
92 }
93}
94
95impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> {
96 type Lifted = ty::TraitPredicate<'tcx>;
a7813a04
XL
97 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
98 -> Option<ty::TraitPredicate<'tcx>> {
e9174d1e
SL
99 tcx.lift(&self.trait_ref).map(|trait_ref| ty::TraitPredicate {
100 trait_ref: trait_ref
101 })
102 }
103}
104
105impl<'a, 'tcx> Lift<'tcx> for ty::EquatePredicate<'a> {
106 type Lifted = ty::EquatePredicate<'tcx>;
a7813a04
XL
107 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
108 -> Option<ty::EquatePredicate<'tcx>> {
e9174d1e
SL
109 tcx.lift(&(self.0, self.1)).map(|(a, b)| ty::EquatePredicate(a, b))
110 }
111}
112
113impl<'tcx, A: Copy+Lift<'tcx>, B: Copy+Lift<'tcx>> Lift<'tcx> for ty::OutlivesPredicate<A, B> {
114 type Lifted = ty::OutlivesPredicate<A::Lifted, B::Lifted>;
a7813a04 115 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
e9174d1e
SL
116 tcx.lift(&(self.0, self.1)).map(|(a, b)| ty::OutlivesPredicate(a, b))
117 }
118}
119
5bcae85e
SL
120impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionTy<'a> {
121 type Lifted = ty::ProjectionTy<'tcx>;
122 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
123 -> Option<ty::ProjectionTy<'tcx>> {
124 tcx.lift(&self.trait_ref).map(|trait_ref| {
125 ty::ProjectionTy {
126 trait_ref: trait_ref,
127 item_name: self.item_name
128 }
129 })
130 }
131}
132
e9174d1e
SL
133impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionPredicate<'a> {
134 type Lifted = ty::ProjectionPredicate<'tcx>;
a7813a04
XL
135 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
136 -> Option<ty::ProjectionPredicate<'tcx>> {
5bcae85e 137 tcx.lift(&(self.projection_ty, self.ty)).map(|(projection_ty, ty)| {
e9174d1e 138 ty::ProjectionPredicate {
5bcae85e 139 projection_ty: projection_ty,
e9174d1e
SL
140 ty: ty
141 }
142 })
143 }
144}
145
9e0c209e
SL
146impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> {
147 type Lifted = ty::ExistentialProjection<'tcx>;
148 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
149 tcx.lift(&(self.trait_ref, self.ty)).map(|(trait_ref, ty)| {
150 ty::ExistentialProjection {
151 trait_ref: trait_ref,
152 item_name: self.item_name,
153 ty: ty
154 }
155 })
156 }
157}
158
a7813a04
XL
159impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> {
160 type Lifted = ty::Predicate<'tcx>;
161 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
162 match *self {
163 ty::Predicate::Trait(ref binder) => {
164 tcx.lift(binder).map(ty::Predicate::Trait)
165 }
166 ty::Predicate::Equate(ref binder) => {
167 tcx.lift(binder).map(ty::Predicate::Equate)
168 }
169 ty::Predicate::RegionOutlives(ref binder) => {
170 tcx.lift(binder).map(ty::Predicate::RegionOutlives)
171 }
172 ty::Predicate::TypeOutlives(ref binder) => {
173 tcx.lift(binder).map(ty::Predicate::TypeOutlives)
174 }
175 ty::Predicate::Projection(ref binder) => {
176 tcx.lift(binder).map(ty::Predicate::Projection)
177 }
178 ty::Predicate::WellFormed(ty) => {
179 tcx.lift(&ty).map(ty::Predicate::WellFormed)
180 }
a7813a04
XL
181 ty::Predicate::ClosureKind(closure_def_id, kind) => {
182 Some(ty::Predicate::ClosureKind(closure_def_id, kind))
183 }
184 ty::Predicate::ObjectSafe(trait_def_id) => {
185 Some(ty::Predicate::ObjectSafe(trait_def_id))
186 }
187 }
188 }
189}
190
e9174d1e
SL
191impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<T> {
192 type Lifted = ty::Binder<T::Lifted>;
a7813a04 193 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
e9174d1e
SL
194 tcx.lift(&self.0).map(|x| ty::Binder(x))
195 }
196}
197
a7813a04
XL
198impl<'a, 'tcx> Lift<'tcx> for ty::ClosureSubsts<'a> {
199 type Lifted = ty::ClosureSubsts<'tcx>;
200 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
201 tcx.lift(&(self.func_substs, self.upvar_tys)).map(|(substs, upvar_tys)| {
202 ty::ClosureSubsts {
203 func_substs: substs,
204 upvar_tys: upvar_tys
205 }
206 })
207 }
208}
209
210impl<'a, 'tcx> Lift<'tcx> for ty::ItemSubsts<'a> {
211 type Lifted = ty::ItemSubsts<'tcx>;
212 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
213 tcx.lift(&self.substs).map(|substs| {
214 ty::ItemSubsts {
215 substs: substs
216 }
217 })
218 }
219}
220
c30ab7b3
SL
221impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
222 type Lifted = ty::adjustment::AutoBorrow<'tcx>;
a7813a04
XL
223 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
224 match *self {
c30ab7b3
SL
225 ty::adjustment::AutoBorrow::Ref(r, m) => {
226 tcx.lift(&r).map(|r| ty::adjustment::AutoBorrow::Ref(r, m))
a7813a04 227 }
c30ab7b3
SL
228 ty::adjustment::AutoBorrow::RawPtr(m) => {
229 Some(ty::adjustment::AutoBorrow::RawPtr(m))
a7813a04
XL
230 }
231 }
232 }
233}
234
a7813a04
XL
235impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> {
236 type Lifted = ty::FnSig<'tcx>;
237 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
238 tcx.lift(&self.inputs[..]).and_then(|inputs| {
239 tcx.lift(&self.output).map(|output| {
240 ty::FnSig {
241 inputs: inputs,
242 output: output,
243 variadic: self.variadic
244 }
245 })
246 })
247 }
248}
249
250impl<'a, 'tcx> Lift<'tcx> for ty::ClosureTy<'a> {
251 type Lifted = ty::ClosureTy<'tcx>;
252 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
253 tcx.lift(&self.sig).map(|sig| {
254 ty::ClosureTy {
255 sig: sig,
256 unsafety: self.unsafety,
257 abi: self.abi
258 }
259 })
260 }
261}
262
263impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::error::ExpectedFound<T> {
264 type Lifted = ty::error::ExpectedFound<T::Lifted>;
265 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
266 tcx.lift(&self.expected).and_then(|expected| {
267 tcx.lift(&self.found).map(|found| {
268 ty::error::ExpectedFound {
269 expected: expected,
270 found: found
271 }
272 })
273 })
274 }
275}
276
277impl<'a, 'tcx> Lift<'tcx> for type_variable::Default<'a> {
278 type Lifted = type_variable::Default<'tcx>;
279 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
280 tcx.lift(&self.ty).map(|ty| {
281 type_variable::Default {
282 ty: ty,
283 origin_span: self.origin_span,
284 def_id: self.def_id
285 }
286 })
287 }
288}
289
290impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
291 type Lifted = ty::error::TypeError<'tcx>;
292 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
293 use ty::error::TypeError::*;
294
295 Some(match *self {
296 Mismatch => Mismatch,
297 UnsafetyMismatch(x) => UnsafetyMismatch(x),
298 AbiMismatch(x) => AbiMismatch(x),
299 Mutability => Mutability,
a7813a04
XL
300 TupleSize(x) => TupleSize(x),
301 FixedArraySize(x) => FixedArraySize(x),
a7813a04 302 ArgCount => ArgCount,
9e0c209e
SL
303 RegionsDoesNotOutlive(a, b) => {
304 return tcx.lift(&(a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b))
305 }
306 RegionsNotSame(a, b) => {
307 return tcx.lift(&(a, b)).map(|(a, b)| RegionsNotSame(a, b))
308 }
309 RegionsNoOverlap(a, b) => {
310 return tcx.lift(&(a, b)).map(|(a, b)| RegionsNoOverlap(a, b))
311 }
a7813a04 312 RegionsInsufficientlyPolymorphic(a, b) => {
9e0c209e
SL
313 return tcx.lift(&b).map(|b| RegionsInsufficientlyPolymorphic(a, b))
314 }
315 RegionsOverlyPolymorphic(a, b) => {
316 return tcx.lift(&b).map(|b| RegionsOverlyPolymorphic(a, b))
a7813a04 317 }
a7813a04
XL
318 IntMismatch(x) => IntMismatch(x),
319 FloatMismatch(x) => FloatMismatch(x),
320 Traits(x) => Traits(x),
321 BuiltinBoundsMismatch(x) => BuiltinBoundsMismatch(x),
322 VariadicMismatch(x) => VariadicMismatch(x),
323 CyclicTy => CyclicTy,
a7813a04
XL
324 ProjectionNameMismatched(x) => ProjectionNameMismatched(x),
325 ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
326
327 Sorts(ref x) => return tcx.lift(x).map(Sorts),
328 TyParamDefaultMismatch(ref x) => {
329 return tcx.lift(x).map(TyParamDefaultMismatch)
330 }
331 })
332 }
333}
334
e9174d1e
SL
335///////////////////////////////////////////////////////////////////////////
336// TypeFoldable implementations.
337//
338// Ideally, each type should invoke `folder.fold_foo(self)` and
339// nothing else. In some cases, though, we haven't gotten around to
340// adding methods on the `folder` yet, and thus the folding is
341// hard-coded here. This is less-flexible, because folders cannot
342// override the behavior, but there are a lot of random types and one
343// can easily refactor the folding into the TypeFolder trait as
344// needed.
345
346macro_rules! CopyImpls {
347 ($($ty:ty),+) => {
348 $(
349 impl<'tcx> TypeFoldable<'tcx> for $ty {
a7813a04 350 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _: &mut F) -> $ty {
e9174d1e
SL
351 *self
352 }
9cc50fc6
SL
353
354 fn super_visit_with<F: TypeVisitor<'tcx>>(&self, _: &mut F) -> bool {
355 false
356 }
e9174d1e
SL
357 }
358 )+
359 }
360}
361
362CopyImpls! { (), hir::Unsafety, abi::Abi }
363
364impl<'tcx, T:TypeFoldable<'tcx>, U:TypeFoldable<'tcx>> TypeFoldable<'tcx> for (T, U) {
a7813a04 365 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> (T, U) {
e9174d1e
SL
366 (self.0.fold_with(folder), self.1.fold_with(folder))
367 }
9cc50fc6
SL
368
369 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
370 self.0.visit_with(visitor) || self.1.visit_with(visitor)
371 }
e9174d1e
SL
372}
373
374impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Option<T> {
a7813a04 375 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
376 self.as_ref().map(|t| t.fold_with(folder))
377 }
9cc50fc6
SL
378
379 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
380 self.iter().any(|t| t.visit_with(visitor))
381 }
e9174d1e
SL
382}
383
384impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
a7813a04 385 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
386 Rc::new((**self).fold_with(folder))
387 }
9cc50fc6
SL
388
389 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
390 (**self).visit_with(visitor)
391 }
e9174d1e
SL
392}
393
394impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> {
a7813a04 395 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
396 let content: T = (**self).fold_with(folder);
397 box content
398 }
9cc50fc6
SL
399
400 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
401 (**self).visit_with(visitor)
402 }
e9174d1e
SL
403}
404
405impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
a7813a04 406 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
407 self.iter().map(|t| t.fold_with(folder)).collect()
408 }
9cc50fc6
SL
409
410 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
411 self.iter().any(|t| t.visit_with(visitor))
412 }
e9174d1e
SL
413}
414
415impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
a7813a04 416 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
54a0048b 417 ty::Binder(self.0.fold_with(folder))
9cc50fc6
SL
418 }
419
a7813a04 420 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
421 folder.fold_binder(self)
422 }
9cc50fc6
SL
423
424 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
54a0048b
SL
425 self.0.visit_with(visitor)
426 }
427
428 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
429 visitor.visit_binder(self)
9cc50fc6 430 }
e9174d1e
SL
431}
432
9e0c209e 433impl<'tcx> TypeFoldable<'tcx> for ty::TraitObject<'tcx> {
a7813a04 434 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
9e0c209e 435 ty::TraitObject {
9cc50fc6 436 principal: self.principal.fold_with(folder),
9e0c209e
SL
437 region_bound: self.region_bound.fold_with(folder),
438 builtin_bounds: self.builtin_bounds,
439 projection_bounds: self.projection_bounds.fold_with(folder),
9cc50fc6
SL
440 }
441 }
442
443 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
9e0c209e
SL
444 self.principal.visit_with(visitor) ||
445 self.region_bound.visit_with(visitor) ||
446 self.projection_bounds.visit_with(visitor)
9cc50fc6 447 }
e9174d1e
SL
448}
449
9e0c209e 450impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Slice<Ty<'tcx>> {
a7813a04 451 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
c30ab7b3
SL
452 let v = self.iter().map(|t| t.fold_with(folder)).collect::<AccumulateVec<[_; 8]>>();
453 folder.tcx().intern_type_list(&v)
a7813a04
XL
454 }
455
456 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
457 self.iter().any(|t| t.visit_with(visitor))
458 }
459}
460
e9174d1e 461impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
a7813a04 462 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
9cc50fc6
SL
463 let sty = match self.sty {
464 ty::TyBox(typ) => ty::TyBox(typ.fold_with(folder)),
a7813a04 465 ty::TyRawPtr(tm) => ty::TyRawPtr(tm.fold_with(folder)),
9cc50fc6
SL
466 ty::TyArray(typ, sz) => ty::TyArray(typ.fold_with(folder), sz),
467 ty::TySlice(typ) => ty::TySlice(typ.fold_with(folder)),
9e0c209e 468 ty::TyAdt(tid, substs) => ty::TyAdt(tid, substs.fold_with(folder)),
9cc50fc6 469 ty::TyTrait(ref trait_ty) => ty::TyTrait(trait_ty.fold_with(folder)),
a7813a04
XL
470 ty::TyTuple(ts) => ty::TyTuple(ts.fold_with(folder)),
471 ty::TyFnDef(def_id, substs, f) => {
54a0048b 472 ty::TyFnDef(def_id,
a7813a04
XL
473 substs.fold_with(folder),
474 f.fold_with(folder))
9cc50fc6 475 }
a7813a04
XL
476 ty::TyFnPtr(f) => ty::TyFnPtr(f.fold_with(folder)),
477 ty::TyRef(ref r, tm) => {
478 ty::TyRef(r.fold_with(folder), tm.fold_with(folder))
9cc50fc6 479 }
a7813a04 480 ty::TyClosure(did, substs) => ty::TyClosure(did, substs.fold_with(folder)),
9cc50fc6 481 ty::TyProjection(ref data) => ty::TyProjection(data.fold_with(folder)),
5bcae85e 482 ty::TyAnon(did, substs) => ty::TyAnon(did, substs.fold_with(folder)),
9cc50fc6
SL
483 ty::TyBool | ty::TyChar | ty::TyStr | ty::TyInt(_) |
484 ty::TyUint(_) | ty::TyFloat(_) | ty::TyError | ty::TyInfer(_) |
5bcae85e 485 ty::TyParam(..) | ty::TyNever => self.sty.clone(),
9cc50fc6
SL
486 };
487 folder.tcx().mk_ty(sty)
488 }
489
a7813a04 490 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
491 folder.fold_ty(*self)
492 }
9cc50fc6
SL
493
494 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
495 match self.sty {
496 ty::TyBox(typ) => typ.visit_with(visitor),
497 ty::TyRawPtr(ref tm) => tm.visit_with(visitor),
498 ty::TyArray(typ, _sz) => typ.visit_with(visitor),
499 ty::TySlice(typ) => typ.visit_with(visitor),
9e0c209e 500 ty::TyAdt(_, substs) => substs.visit_with(visitor),
9cc50fc6 501 ty::TyTrait(ref trait_ty) => trait_ty.visit_with(visitor),
a7813a04 502 ty::TyTuple(ts) => ts.visit_with(visitor),
54a0048b
SL
503 ty::TyFnDef(_, substs, ref f) => {
504 substs.visit_with(visitor) || f.visit_with(visitor)
505 }
506 ty::TyFnPtr(ref f) => f.visit_with(visitor),
9cc50fc6 507 ty::TyRef(r, ref tm) => r.visit_with(visitor) || tm.visit_with(visitor),
9cc50fc6
SL
508 ty::TyClosure(_did, ref substs) => substs.visit_with(visitor),
509 ty::TyProjection(ref data) => data.visit_with(visitor),
5bcae85e 510 ty::TyAnon(_, ref substs) => substs.visit_with(visitor),
9cc50fc6
SL
511 ty::TyBool | ty::TyChar | ty::TyStr | ty::TyInt(_) |
512 ty::TyUint(_) | ty::TyFloat(_) | ty::TyError | ty::TyInfer(_) |
5bcae85e 513 ty::TyParam(..) | ty::TyNever => false,
9cc50fc6
SL
514 }
515 }
516
517 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
518 visitor.visit_ty(self)
519 }
e9174d1e
SL
520}
521
a7813a04
XL
522impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::BareFnTy<'tcx> {
523 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
524 let fty = ty::BareFnTy {
525 sig: self.sig.fold_with(folder),
526 abi: self.abi,
527 unsafety: self.unsafety
528 };
529 folder.tcx().mk_bare_fn(fty)
9cc50fc6
SL
530 }
531
a7813a04 532 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
533 folder.fold_bare_fn_ty(self)
534 }
9cc50fc6
SL
535
536 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
537 self.sig.visit_with(visitor)
538 }
e9174d1e
SL
539}
540
541impl<'tcx> TypeFoldable<'tcx> for ty::ClosureTy<'tcx> {
a7813a04 542 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
9cc50fc6
SL
543 ty::ClosureTy {
544 sig: self.sig.fold_with(folder),
545 unsafety: self.unsafety,
546 abi: self.abi,
547 }
548 }
549
a7813a04 550 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
551 folder.fold_closure_ty(self)
552 }
9cc50fc6
SL
553
554 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
555 self.sig.visit_with(visitor)
556 }
e9174d1e
SL
557}
558
559impl<'tcx> TypeFoldable<'tcx> for ty::TypeAndMut<'tcx> {
a7813a04 560 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
9cc50fc6
SL
561 ty::TypeAndMut { ty: self.ty.fold_with(folder), mutbl: self.mutbl }
562 }
563
a7813a04 564 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
565 folder.fold_mt(self)
566 }
9cc50fc6
SL
567
568 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
569 self.ty.visit_with(visitor)
570 }
e9174d1e
SL
571}
572
e9174d1e 573impl<'tcx> TypeFoldable<'tcx> for ty::FnSig<'tcx> {
a7813a04 574 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
9cc50fc6
SL
575 ty::FnSig { inputs: self.inputs.fold_with(folder),
576 output: self.output.fold_with(folder),
577 variadic: self.variadic }
578 }
579
a7813a04 580 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
581 folder.fold_fn_sig(self)
582 }
9cc50fc6
SL
583
584 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
585 self.inputs.visit_with(visitor) || self.output.visit_with(visitor)
586 }
e9174d1e
SL
587}
588
589impl<'tcx> TypeFoldable<'tcx> for ty::TraitRef<'tcx> {
a7813a04 590 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
9cc50fc6
SL
591 ty::TraitRef {
592 def_id: self.def_id,
a7813a04 593 substs: self.substs.fold_with(folder),
9cc50fc6
SL
594 }
595 }
596
9e0c209e
SL
597 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
598 self.substs.visit_with(visitor)
599 }
600}
601
602impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialTraitRef<'tcx> {
603 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
604 ty::ExistentialTraitRef {
605 def_id: self.def_id,
606 substs: self.substs.fold_with(folder),
607 }
e9174d1e 608 }
9cc50fc6
SL
609
610 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
611 self.substs.visit_with(visitor)
612 }
e9174d1e
SL
613}
614
54a0048b 615impl<'tcx> TypeFoldable<'tcx> for ty::ImplHeader<'tcx> {
a7813a04 616 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
54a0048b
SL
617 ty::ImplHeader {
618 impl_def_id: self.impl_def_id,
619 self_ty: self.self_ty.fold_with(folder),
620 trait_ref: self.trait_ref.map(|t| t.fold_with(folder)),
621 predicates: self.predicates.iter().map(|p| p.fold_with(folder)).collect(),
622 }
623 }
624
a7813a04 625 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
54a0048b
SL
626 folder.fold_impl_header(self)
627 }
628
629 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
630 self.self_ty.visit_with(visitor) ||
631 self.trait_ref.map(|r| r.visit_with(visitor)).unwrap_or(false) ||
632 self.predicates.iter().any(|p| p.visit_with(visitor))
633 }
634}
635
9e0c209e 636impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Region {
a7813a04 637 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _folder: &mut F) -> Self {
9cc50fc6
SL
638 *self
639 }
640
a7813a04 641 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
642 folder.fold_region(*self)
643 }
9cc50fc6
SL
644
645 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
646 false
647 }
648
649 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
650 visitor.visit_region(*self)
651 }
e9174d1e
SL
652}
653
e9174d1e 654impl<'tcx> TypeFoldable<'tcx> for ty::ClosureSubsts<'tcx> {
a7813a04 655 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e 656 ty::ClosureSubsts {
a7813a04 657 func_substs: self.func_substs.fold_with(folder),
e9174d1e
SL
658 upvar_tys: self.upvar_tys.fold_with(folder),
659 }
660 }
9cc50fc6
SL
661
662 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
663 self.func_substs.visit_with(visitor) || self.upvar_tys.visit_with(visitor)
664 }
e9174d1e
SL
665}
666
667impl<'tcx> TypeFoldable<'tcx> for ty::ItemSubsts<'tcx> {
a7813a04 668 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
669 ty::ItemSubsts {
670 substs: self.substs.fold_with(folder),
671 }
672 }
9cc50fc6
SL
673
674 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
675 self.substs.visit_with(visitor)
676 }
e9174d1e
SL
677}
678
c30ab7b3 679impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::AutoBorrow<'tcx> {
a7813a04 680 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
9cc50fc6 681 match *self {
c30ab7b3
SL
682 ty::adjustment::AutoBorrow::Ref(ref r, m) => {
683 ty::adjustment::AutoBorrow::Ref(r.fold_with(folder), m)
9cc50fc6 684 }
c30ab7b3 685 ty::adjustment::AutoBorrow::RawPtr(m) => ty::adjustment::AutoBorrow::RawPtr(m)
9cc50fc6
SL
686 }
687 }
688
a7813a04 689 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
690 folder.fold_autoref(self)
691 }
9cc50fc6
SL
692
693 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
694 match *self {
c30ab7b3
SL
695 ty::adjustment::AutoBorrow::Ref(r, _m) => r.visit_with(visitor),
696 ty::adjustment::AutoBorrow::RawPtr(_m) => false,
9cc50fc6
SL
697 }
698 }
e9174d1e
SL
699}
700
701impl<'tcx> TypeFoldable<'tcx> for ty::BuiltinBounds {
a7813a04 702 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _folder: &mut F) -> Self {
e9174d1e
SL
703 *self
704 }
9cc50fc6
SL
705
706 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
707 false
708 }
e9174d1e
SL
709}
710
e9174d1e 711impl<'tcx> TypeFoldable<'tcx> for ty::TypeParameterDef<'tcx> {
a7813a04 712 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
713 ty::TypeParameterDef {
714 name: self.name,
715 def_id: self.def_id,
e9174d1e
SL
716 index: self.index,
717 default: self.default.fold_with(folder),
718 default_def_id: self.default_def_id,
719 object_lifetime_default: self.object_lifetime_default.fold_with(folder),
c30ab7b3 720 pure_wrt_drop: self.pure_wrt_drop,
e9174d1e
SL
721 }
722 }
9cc50fc6
SL
723
724 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
725 self.default.visit_with(visitor) ||
726 self.object_lifetime_default.visit_with(visitor)
727 }
e9174d1e
SL
728}
729
9e0c209e 730impl<'tcx> TypeFoldable<'tcx> for ty::ObjectLifetimeDefault<'tcx> {
a7813a04 731 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
732 match *self {
733 ty::ObjectLifetimeDefault::Ambiguous =>
734 ty::ObjectLifetimeDefault::Ambiguous,
735
736 ty::ObjectLifetimeDefault::BaseDefault =>
737 ty::ObjectLifetimeDefault::BaseDefault,
738
739 ty::ObjectLifetimeDefault::Specific(r) =>
740 ty::ObjectLifetimeDefault::Specific(r.fold_with(folder)),
741 }
742 }
9cc50fc6
SL
743
744 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
745 match *self {
746 ty::ObjectLifetimeDefault::Specific(r) => r.visit_with(visitor),
747 _ => false,
748 }
749 }
e9174d1e
SL
750}
751
9e0c209e 752impl<'tcx> TypeFoldable<'tcx> for ty::RegionParameterDef<'tcx> {
a7813a04 753 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
754 ty::RegionParameterDef {
755 name: self.name,
756 def_id: self.def_id,
e9174d1e 757 index: self.index,
3157f602 758 bounds: self.bounds.fold_with(folder),
c30ab7b3 759 pure_wrt_drop: self.pure_wrt_drop,
e9174d1e
SL
760 }
761 }
9cc50fc6
SL
762
763 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
764 self.bounds.visit_with(visitor)
765 }
e9174d1e
SL
766}
767
e9174d1e 768impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
a7813a04 769 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
770 match *self {
771 ty::Predicate::Trait(ref a) =>
772 ty::Predicate::Trait(a.fold_with(folder)),
773 ty::Predicate::Equate(ref binder) =>
774 ty::Predicate::Equate(binder.fold_with(folder)),
775 ty::Predicate::RegionOutlives(ref binder) =>
776 ty::Predicate::RegionOutlives(binder.fold_with(folder)),
777 ty::Predicate::TypeOutlives(ref binder) =>
778 ty::Predicate::TypeOutlives(binder.fold_with(folder)),
779 ty::Predicate::Projection(ref binder) =>
780 ty::Predicate::Projection(binder.fold_with(folder)),
781 ty::Predicate::WellFormed(data) =>
782 ty::Predicate::WellFormed(data.fold_with(folder)),
a7813a04
XL
783 ty::Predicate::ClosureKind(closure_def_id, kind) =>
784 ty::Predicate::ClosureKind(closure_def_id, kind),
e9174d1e
SL
785 ty::Predicate::ObjectSafe(trait_def_id) =>
786 ty::Predicate::ObjectSafe(trait_def_id),
787 }
788 }
9cc50fc6
SL
789
790 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
791 match *self {
792 ty::Predicate::Trait(ref a) => a.visit_with(visitor),
793 ty::Predicate::Equate(ref binder) => binder.visit_with(visitor),
794 ty::Predicate::RegionOutlives(ref binder) => binder.visit_with(visitor),
795 ty::Predicate::TypeOutlives(ref binder) => binder.visit_with(visitor),
796 ty::Predicate::Projection(ref binder) => binder.visit_with(visitor),
797 ty::Predicate::WellFormed(data) => data.visit_with(visitor),
a7813a04 798 ty::Predicate::ClosureKind(_closure_def_id, _kind) => false,
9cc50fc6
SL
799 ty::Predicate::ObjectSafe(_trait_def_id) => false,
800 }
801 }
e9174d1e
SL
802}
803
804impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionPredicate<'tcx> {
a7813a04 805 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
806 ty::ProjectionPredicate {
807 projection_ty: self.projection_ty.fold_with(folder),
808 ty: self.ty.fold_with(folder),
809 }
810 }
9cc50fc6
SL
811
812 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
813 self.projection_ty.visit_with(visitor) || self.ty.visit_with(visitor)
814 }
e9174d1e
SL
815}
816
9e0c209e
SL
817impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialProjection<'tcx> {
818 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
819 ty::ExistentialProjection {
820 trait_ref: self.trait_ref.fold_with(folder),
821 item_name: self.item_name,
822 ty: self.ty.fold_with(folder),
823 }
824 }
825
826 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
827 self.trait_ref.visit_with(visitor) || self.ty.visit_with(visitor)
828 }
829}
830
e9174d1e 831impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionTy<'tcx> {
a7813a04 832 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
833 ty::ProjectionTy {
834 trait_ref: self.trait_ref.fold_with(folder),
835 item_name: self.item_name,
836 }
837 }
9cc50fc6
SL
838
839 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
840 self.trait_ref.visit_with(visitor)
841 }
e9174d1e
SL
842}
843
844impl<'tcx> TypeFoldable<'tcx> for ty::InstantiatedPredicates<'tcx> {
a7813a04 845 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
846 ty::InstantiatedPredicates {
847 predicates: self.predicates.fold_with(folder),
848 }
849 }
9cc50fc6
SL
850
851 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
852 self.predicates.visit_with(visitor)
853 }
e9174d1e
SL
854}
855
856impl<'tcx> TypeFoldable<'tcx> for ty::EquatePredicate<'tcx> {
a7813a04 857 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
858 ty::EquatePredicate(self.0.fold_with(folder),
859 self.1.fold_with(folder))
860 }
9cc50fc6
SL
861
862 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
863 self.0.visit_with(visitor) || self.1.visit_with(visitor)
864 }
e9174d1e
SL
865}
866
867impl<'tcx> TypeFoldable<'tcx> for ty::TraitPredicate<'tcx> {
a7813a04 868 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
869 ty::TraitPredicate {
870 trait_ref: self.trait_ref.fold_with(folder)
871 }
872 }
9cc50fc6
SL
873
874 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
875 self.trait_ref.visit_with(visitor)
876 }
e9174d1e
SL
877}
878
879impl<'tcx,T,U> TypeFoldable<'tcx> for ty::OutlivesPredicate<T,U>
880 where T : TypeFoldable<'tcx>,
881 U : TypeFoldable<'tcx>,
882{
a7813a04 883 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
884 ty::OutlivesPredicate(self.0.fold_with(folder),
885 self.1.fold_with(folder))
886 }
9cc50fc6
SL
887
888 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
889 self.0.visit_with(visitor) || self.1.visit_with(visitor)
890 }
e9174d1e
SL
891}
892
893impl<'tcx> TypeFoldable<'tcx> for ty::ClosureUpvar<'tcx> {
a7813a04 894 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
e9174d1e
SL
895 ty::ClosureUpvar {
896 def: self.def,
897 span: self.span,
898 ty: self.ty.fold_with(folder),
899 }
900 }
9cc50fc6
SL
901
902 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
903 self.ty.visit_with(visitor)
904 }
e9174d1e
SL
905}
906
5bcae85e
SL
907impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::error::ExpectedFound<T> {
908 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
909 ty::error::ExpectedFound {
910 expected: self.expected.fold_with(folder),
911 found: self.found.fold_with(folder),
912 }
913 }
914
915 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
916 self.expected.visit_with(visitor) || self.found.visit_with(visitor)
917 }
918}