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.
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.
11 use ty
::subst
::{self, VecPerParamSpace}
;
13 use ty
::{self, Lift, TraitRef, Ty, TyCtxt}
;
14 use ty
::fold
::{TypeFoldable, TypeFolder, TypeVisitor}
;
22 ///////////////////////////////////////////////////////////////////////////
23 // Lift implementations
25 impl<'tcx
, A
: Lift
<'tcx
>, B
: Lift
<'tcx
>> Lift
<'tcx
> for (A
, B
) {
26 type Lifted
= (A
::Lifted
, B
::Lifted
);
27 fn lift_to_tcx(&self, tcx
: &TyCtxt
<'tcx
>) -> Option
<Self::Lifted
> {
28 tcx
.lift(&self.0).and_then(|a
| tcx
.lift(&self.1).map(|b
| (a
, b
)))
32 impl<'tcx
, T
: Lift
<'tcx
>> Lift
<'tcx
> for [T
] {
33 type Lifted
= Vec
<T
::Lifted
>;
34 fn lift_to_tcx(&self, tcx
: &TyCtxt
<'tcx
>) -> Option
<Self::Lifted
> {
35 // type annotation needed to inform `projection_must_outlive`
36 let mut result
: Vec
<<T
as Lift
<'tcx
>>::Lifted
>
37 = Vec
::with_capacity(self.len());
39 if let Some(value
) = tcx
.lift(x
) {
49 impl<'tcx
> Lift
<'tcx
> for ty
::Region
{
51 fn lift_to_tcx(&self, _
: &TyCtxt
<'tcx
>) -> Option
<ty
::Region
> {
56 impl<'a
, 'tcx
> Lift
<'tcx
> for TraitRef
<'a
> {
57 type Lifted
= TraitRef
<'tcx
>;
58 fn lift_to_tcx(&self, tcx
: &TyCtxt
<'tcx
>) -> Option
<TraitRef
<'tcx
>> {
59 tcx
.lift(&self.substs
).map(|substs
| TraitRef
{
66 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::TraitPredicate
<'a
> {
67 type Lifted
= ty
::TraitPredicate
<'tcx
>;
68 fn lift_to_tcx(&self, tcx
: &TyCtxt
<'tcx
>) -> Option
<ty
::TraitPredicate
<'tcx
>> {
69 tcx
.lift(&self.trait_ref
).map(|trait_ref
| ty
::TraitPredicate
{
75 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::EquatePredicate
<'a
> {
76 type Lifted
= ty
::EquatePredicate
<'tcx
>;
77 fn lift_to_tcx(&self, tcx
: &TyCtxt
<'tcx
>) -> Option
<ty
::EquatePredicate
<'tcx
>> {
78 tcx
.lift(&(self.0, self.1)).map(|(a
, b
)| ty
::EquatePredicate(a
, b
))
82 impl<'tcx
, A
: Copy
+Lift
<'tcx
>, B
: Copy
+Lift
<'tcx
>> Lift
<'tcx
> for ty
::OutlivesPredicate
<A
, B
> {
83 type Lifted
= ty
::OutlivesPredicate
<A
::Lifted
, B
::Lifted
>;
84 fn lift_to_tcx(&self, tcx
: &TyCtxt
<'tcx
>) -> Option
<Self::Lifted
> {
85 tcx
.lift(&(self.0, self.1)).map(|(a
, b
)| ty
::OutlivesPredicate(a
, b
))
89 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::ProjectionPredicate
<'a
> {
90 type Lifted
= ty
::ProjectionPredicate
<'tcx
>;
91 fn lift_to_tcx(&self, tcx
: &TyCtxt
<'tcx
>) -> Option
<ty
::ProjectionPredicate
<'tcx
>> {
92 tcx
.lift(&(self.projection_ty
.trait_ref
, self.ty
)).map(|(trait_ref
, ty
)| {
93 ty
::ProjectionPredicate
{
94 projection_ty
: ty
::ProjectionTy
{
96 item_name
: self.projection_ty
.item_name
104 impl<'tcx
, T
: Lift
<'tcx
>> Lift
<'tcx
> for ty
::Binder
<T
> {
105 type Lifted
= ty
::Binder
<T
::Lifted
>;
106 fn lift_to_tcx(&self, tcx
: &TyCtxt
<'tcx
>) -> Option
<Self::Lifted
> {
107 tcx
.lift(&self.0).map(|x
| ty
::Binder(x
))
111 ///////////////////////////////////////////////////////////////////////////
112 // TypeFoldable implementations.
114 // Ideally, each type should invoke `folder.fold_foo(self)` and
115 // nothing else. In some cases, though, we haven't gotten around to
116 // adding methods on the `folder` yet, and thus the folding is
117 // hard-coded here. This is less-flexible, because folders cannot
118 // override the behavior, but there are a lot of random types and one
119 // can easily refactor the folding into the TypeFolder trait as
122 macro_rules
! CopyImpls
{
125 impl<'tcx
> TypeFoldable
<'tcx
> for $ty
{
126 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, _
: &mut F
) -> $ty
{
130 fn super_visit_with
<F
: TypeVisitor
<'tcx
>>(&self, _
: &mut F
) -> bool
{
138 CopyImpls
! { (), hir::Unsafety, abi::Abi }
140 impl<'tcx
, T
:TypeFoldable
<'tcx
>, U
:TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for (T
, U
) {
141 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> (T
, U
) {
142 (self.0.fold_with
(folder
), self.1.fold_with
(folder
))
145 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
146 self.0.visit_with(visitor
) || self.1.visit_with(visitor
)
150 impl<'tcx
, T
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for Option
<T
> {
151 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
152 self.as_ref().map(|t
| t
.fold_with(folder
))
155 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
156 self.iter().any(|t
| t
.visit_with(visitor
))
160 impl<'tcx
, T
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for Rc
<T
> {
161 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
162 Rc
::new((**self).fold_with(folder
))
165 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
166 (**self).visit_with(visitor
)
170 impl<'tcx
, T
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for Box
<T
> {
171 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
172 let content
: T
= (**self).fold_with(folder
);
176 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
177 (**self).visit_with(visitor
)
181 impl<'tcx
, T
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for Vec
<T
> {
182 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
183 self.iter().map(|t
| t
.fold_with(folder
)).collect()
186 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
187 self.iter().any(|t
| t
.visit_with(visitor
))
191 impl<'tcx
, T
:TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for ty
::Binder
<T
> {
192 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
193 ty
::Binder(self.0.fold_with
(folder
))
196 fn fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
197 folder
.fold_binder(self)
200 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
201 self.0.visit_with(visitor
)
204 fn visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
205 visitor
.visit_binder(self)
209 impl<'tcx
, T
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for P
<[T
]> {
210 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
211 self.iter().map(|t
| t
.fold_with(folder
)).collect()
214 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
215 self.iter().any(|t
| t
.visit_with(visitor
))
219 impl<'tcx
, T
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for VecPerParamSpace
<T
> {
220 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
221 self.map(|elem
| elem
.fold_with(folder
))
224 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
225 self.iter().any(|elem
| elem
.visit_with(visitor
))
229 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::TraitTy
<'tcx
> {
230 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
232 principal
: self.principal
.fold_with(folder
),
233 bounds
: self.bounds
.fold_with(folder
),
237 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
238 self.principal
.visit_with(visitor
) || self.bounds
.visit_with(visitor
)
242 impl<'tcx
> TypeFoldable
<'tcx
> for Ty
<'tcx
> {
243 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
244 let sty
= match self.sty
{
245 ty
::TyBox(typ
) => ty
::TyBox(typ
.fold_with(folder
)),
246 ty
::TyRawPtr(ref tm
) => ty
::TyRawPtr(tm
.fold_with(folder
)),
247 ty
::TyArray(typ
, sz
) => ty
::TyArray(typ
.fold_with(folder
), sz
),
248 ty
::TySlice(typ
) => ty
::TySlice(typ
.fold_with(folder
)),
249 ty
::TyEnum(tid
, ref substs
) => {
250 let substs
= substs
.fold_with(folder
);
251 ty
::TyEnum(tid
, folder
.tcx().mk_substs(substs
))
253 ty
::TyTrait(ref trait_ty
) => ty
::TyTrait(trait_ty
.fold_with(folder
)),
254 ty
::TyTuple(ref ts
) => ty
::TyTuple(ts
.fold_with(folder
)),
255 ty
::TyFnDef(def_id
, substs
, ref f
) => {
256 let substs
= substs
.fold_with(folder
);
257 let bfn
= f
.fold_with(folder
);
259 folder
.tcx().mk_substs(substs
),
260 folder
.tcx().mk_bare_fn(bfn
))
262 ty
::TyFnPtr(ref f
) => {
263 let bfn
= f
.fold_with(folder
);
264 ty
::TyFnPtr(folder
.tcx().mk_bare_fn(bfn
))
266 ty
::TyRef(r
, ref tm
) => {
267 let r
= r
.fold_with(folder
);
268 ty
::TyRef(folder
.tcx().mk_region(r
), tm
.fold_with(folder
))
270 ty
::TyStruct(did
, ref substs
) => {
271 let substs
= substs
.fold_with(folder
);
272 ty
::TyStruct(did
, folder
.tcx().mk_substs(substs
))
274 ty
::TyClosure(did
, ref substs
) => {
275 ty
::TyClosure(did
, substs
.fold_with(folder
))
277 ty
::TyProjection(ref data
) => ty
::TyProjection(data
.fold_with(folder
)),
278 ty
::TyBool
| ty
::TyChar
| ty
::TyStr
| ty
::TyInt(_
) |
279 ty
::TyUint(_
) | ty
::TyFloat(_
) | ty
::TyError
| ty
::TyInfer(_
) |
280 ty
::TyParam(..) => self.sty
.clone(),
282 folder
.tcx().mk_ty(sty
)
285 fn fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
286 folder
.fold_ty(*self)
289 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
291 ty
::TyBox(typ
) => typ
.visit_with(visitor
),
292 ty
::TyRawPtr(ref tm
) => tm
.visit_with(visitor
),
293 ty
::TyArray(typ
, _sz
) => typ
.visit_with(visitor
),
294 ty
::TySlice(typ
) => typ
.visit_with(visitor
),
295 ty
::TyEnum(_tid
, ref substs
) => substs
.visit_with(visitor
),
296 ty
::TyTrait(ref trait_ty
) => trait_ty
.visit_with(visitor
),
297 ty
::TyTuple(ref ts
) => ts
.visit_with(visitor
),
298 ty
::TyFnDef(_
, substs
, ref f
) => {
299 substs
.visit_with(visitor
) || f
.visit_with(visitor
)
301 ty
::TyFnPtr(ref f
) => f
.visit_with(visitor
),
302 ty
::TyRef(r
, ref tm
) => r
.visit_with(visitor
) || tm
.visit_with(visitor
),
303 ty
::TyStruct(_did
, ref substs
) => substs
.visit_with(visitor
),
304 ty
::TyClosure(_did
, ref substs
) => substs
.visit_with(visitor
),
305 ty
::TyProjection(ref data
) => data
.visit_with(visitor
),
306 ty
::TyBool
| ty
::TyChar
| ty
::TyStr
| ty
::TyInt(_
) |
307 ty
::TyUint(_
) | ty
::TyFloat(_
) | ty
::TyError
| ty
::TyInfer(_
) |
308 ty
::TyParam(..) => false,
312 fn visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
313 visitor
.visit_ty(self)
317 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::BareFnTy
<'tcx
> {
318 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
319 ty
::BareFnTy
{ sig
: self.sig
.fold_with(folder
),
321 unsafety
: self.unsafety
}
324 fn fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
325 folder
.fold_bare_fn_ty(self)
328 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
329 self.sig
.visit_with(visitor
)
333 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ClosureTy
<'tcx
> {
334 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
336 sig
: self.sig
.fold_with(folder
),
337 unsafety
: self.unsafety
,
342 fn fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
343 folder
.fold_closure_ty(self)
346 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
347 self.sig
.visit_with(visitor
)
351 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::TypeAndMut
<'tcx
> {
352 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
353 ty
::TypeAndMut { ty: self.ty.fold_with(folder), mutbl: self.mutbl }
356 fn fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
360 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
361 self.ty
.visit_with(visitor
)
365 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::FnOutput
<'tcx
> {
366 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
368 ty
::FnConverging(ref ty
) => ty
::FnConverging(ty
.fold_with(folder
)),
369 ty
::FnDiverging
=> ty
::FnDiverging
373 fn fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
374 folder
.fold_output(self)
377 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
379 ty
::FnConverging(ref ty
) => ty
.visit_with(visitor
),
380 ty
::FnDiverging
=> false,
385 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::FnSig
<'tcx
> {
386 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
387 ty
::FnSig
{ inputs
: self.inputs
.fold_with(folder
),
388 output
: self.output
.fold_with(folder
),
389 variadic
: self.variadic
}
392 fn fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
393 folder
.fold_fn_sig(self)
396 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
397 self.inputs
.visit_with(visitor
) || self.output
.visit_with(visitor
)
401 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::TraitRef
<'tcx
> {
402 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
403 let substs
= self.substs
.fold_with(folder
);
406 substs
: folder
.tcx().mk_substs(substs
),
410 fn fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
411 folder
.fold_trait_ref(self)
414 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
415 self.substs
.visit_with(visitor
)
419 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ImplHeader
<'tcx
> {
420 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
422 impl_def_id
: self.impl_def_id
,
423 self_ty
: self.self_ty
.fold_with(folder
),
424 trait_ref
: self.trait_ref
.map(|t
| t
.fold_with(folder
)),
425 predicates
: self.predicates
.iter().map(|p
| p
.fold_with(folder
)).collect(),
429 fn fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
430 folder
.fold_impl_header(self)
433 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
434 self.self_ty
.visit_with(visitor
) ||
435 self.trait_ref
.map(|r
| r
.visit_with(visitor
)).unwrap_or(false) ||
436 self.predicates
.iter().any(|p
| p
.visit_with(visitor
))
440 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::Region
{
441 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, _folder
: &mut F
) -> Self {
445 fn fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
446 folder
.fold_region(*self)
449 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, _visitor
: &mut V
) -> bool
{
453 fn visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
454 visitor
.visit_region(*self)
458 impl<'tcx
> TypeFoldable
<'tcx
> for subst
::Substs
<'tcx
> {
459 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
460 subst
::Substs
{ regions
: self.regions
.fold_with(folder
),
461 types
: self.types
.fold_with(folder
) }
464 fn fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
465 folder
.fold_substs(self)
468 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
469 self.types
.visit_with(visitor
) || self.regions
.visit_with(visitor
)
473 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ClosureSubsts
<'tcx
> {
474 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
475 let func_substs
= self.func_substs
.fold_with(folder
);
477 func_substs
: folder
.tcx().mk_substs(func_substs
),
478 upvar_tys
: self.upvar_tys
.fold_with(folder
),
482 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
483 self.func_substs
.visit_with(visitor
) || self.upvar_tys
.visit_with(visitor
)
487 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ItemSubsts
<'tcx
> {
488 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
490 substs
: self.substs
.fold_with(folder
),
494 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
495 self.substs
.visit_with(visitor
)
499 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::adjustment
::AutoRef
<'tcx
> {
500 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
502 ty
::adjustment
::AutoPtr(r
, m
) => {
503 let r
= r
.fold_with(folder
);
504 ty
::adjustment
::AutoPtr(folder
.tcx().mk_region(r
), m
)
506 ty
::adjustment
::AutoUnsafe(m
) => ty
::adjustment
::AutoUnsafe(m
)
510 fn fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
511 folder
.fold_autoref(self)
514 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
516 ty
::adjustment
::AutoPtr(r
, _m
) => r
.visit_with(visitor
),
517 ty
::adjustment
::AutoUnsafe(_m
) => false,
522 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::BuiltinBounds
{
523 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, _folder
: &mut F
) -> Self {
527 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, _visitor
: &mut V
) -> bool
{
532 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ExistentialBounds
<'tcx
> {
533 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
534 ty
::ExistentialBounds
{
535 region_bound
: self.region_bound
.fold_with(folder
),
536 builtin_bounds
: self.builtin_bounds
,
537 projection_bounds
: self.projection_bounds
.fold_with(folder
),
541 fn fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
542 folder
.fold_existential_bounds(self)
545 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
546 self.region_bound
.visit_with(visitor
) || self.projection_bounds
.visit_with(visitor
)
550 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::TypeParameterDef
<'tcx
> {
551 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
552 ty
::TypeParameterDef
{
557 default: self.default.fold_with(folder
),
558 default_def_id
: self.default_def_id
,
559 object_lifetime_default
: self.object_lifetime_default
.fold_with(folder
),
563 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
564 self.default.visit_with(visitor
) ||
565 self.object_lifetime_default
.visit_with(visitor
)
569 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ObjectLifetimeDefault
{
570 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
572 ty
::ObjectLifetimeDefault
::Ambiguous
=>
573 ty
::ObjectLifetimeDefault
::Ambiguous
,
575 ty
::ObjectLifetimeDefault
::BaseDefault
=>
576 ty
::ObjectLifetimeDefault
::BaseDefault
,
578 ty
::ObjectLifetimeDefault
::Specific(r
) =>
579 ty
::ObjectLifetimeDefault
::Specific(r
.fold_with(folder
)),
583 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
585 ty
::ObjectLifetimeDefault
::Specific(r
) => r
.visit_with(visitor
),
591 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::RegionParameterDef
{
592 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
593 ty
::RegionParameterDef
{
598 bounds
: self.bounds
.fold_with(folder
)
602 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
603 self.bounds
.visit_with(visitor
)
607 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::Generics
<'tcx
> {
608 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
610 types
: self.types
.fold_with(folder
),
611 regions
: self.regions
.fold_with(folder
),
615 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
616 self.types
.visit_with(visitor
) || self.regions
.visit_with(visitor
)
620 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::GenericPredicates
<'tcx
> {
621 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
622 ty
::GenericPredicates
{
623 predicates
: self.predicates
.fold_with(folder
),
627 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
628 self.predicates
.visit_with(visitor
)
632 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::Predicate
<'tcx
> {
633 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
635 ty
::Predicate
::Trait(ref a
) =>
636 ty
::Predicate
::Trait(a
.fold_with(folder
)),
637 ty
::Predicate
::Equate(ref binder
) =>
638 ty
::Predicate
::Equate(binder
.fold_with(folder
)),
639 ty
::Predicate
::RegionOutlives(ref binder
) =>
640 ty
::Predicate
::RegionOutlives(binder
.fold_with(folder
)),
641 ty
::Predicate
::TypeOutlives(ref binder
) =>
642 ty
::Predicate
::TypeOutlives(binder
.fold_with(folder
)),
643 ty
::Predicate
::Projection(ref binder
) =>
644 ty
::Predicate
::Projection(binder
.fold_with(folder
)),
645 ty
::Predicate
::WellFormed(data
) =>
646 ty
::Predicate
::WellFormed(data
.fold_with(folder
)),
647 ty
::Predicate
::ObjectSafe(trait_def_id
) =>
648 ty
::Predicate
::ObjectSafe(trait_def_id
),
652 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
654 ty
::Predicate
::Trait(ref a
) => a
.visit_with(visitor
),
655 ty
::Predicate
::Equate(ref binder
) => binder
.visit_with(visitor
),
656 ty
::Predicate
::RegionOutlives(ref binder
) => binder
.visit_with(visitor
),
657 ty
::Predicate
::TypeOutlives(ref binder
) => binder
.visit_with(visitor
),
658 ty
::Predicate
::Projection(ref binder
) => binder
.visit_with(visitor
),
659 ty
::Predicate
::WellFormed(data
) => data
.visit_with(visitor
),
660 ty
::Predicate
::ObjectSafe(_trait_def_id
) => false,
665 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ProjectionPredicate
<'tcx
> {
666 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
667 ty
::ProjectionPredicate
{
668 projection_ty
: self.projection_ty
.fold_with(folder
),
669 ty
: self.ty
.fold_with(folder
),
673 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
674 self.projection_ty
.visit_with(visitor
) || self.ty
.visit_with(visitor
)
678 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ProjectionTy
<'tcx
> {
679 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
681 trait_ref
: self.trait_ref
.fold_with(folder
),
682 item_name
: self.item_name
,
686 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
687 self.trait_ref
.visit_with(visitor
)
691 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::InstantiatedPredicates
<'tcx
> {
692 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
693 ty
::InstantiatedPredicates
{
694 predicates
: self.predicates
.fold_with(folder
),
698 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
699 self.predicates
.visit_with(visitor
)
703 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::EquatePredicate
<'tcx
> {
704 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
705 ty
::EquatePredicate(self.0.fold_with
(folder
),
706 self.1.fold_with
(folder
))
709 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
710 self.0.visit_with(visitor
) || self.1.visit_with(visitor
)
714 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::TraitPredicate
<'tcx
> {
715 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
717 trait_ref
: self.trait_ref
.fold_with(folder
)
721 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
722 self.trait_ref
.visit_with(visitor
)
726 impl<'tcx
,T
,U
> TypeFoldable
<'tcx
> for ty
::OutlivesPredicate
<T
,U
>
727 where T
: TypeFoldable
<'tcx
>,
728 U
: TypeFoldable
<'tcx
>,
730 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
731 ty
::OutlivesPredicate(self.0.fold_with
(folder
),
732 self.1.fold_with
(folder
))
735 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
736 self.0.visit_with(visitor
) || self.1.visit_with(visitor
)
740 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ClosureUpvar
<'tcx
> {
741 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
745 ty
: self.ty
.fold_with(folder
),
749 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
750 self.ty
.visit_with(visitor
)
754 impl<'a
, 'tcx
> TypeFoldable
<'tcx
> for ty
::ParameterEnvironment
<'a
, 'tcx
> where 'tcx
: 'a
{
755 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
756 ty
::ParameterEnvironment
{
758 free_substs
: self.free_substs
.fold_with(folder
),
759 implicit_region_bound
: self.implicit_region_bound
.fold_with(folder
),
760 caller_bounds
: self.caller_bounds
.fold_with(folder
),
761 selection_cache
: traits
::SelectionCache
::new(),
762 evaluation_cache
: traits
::EvaluationCache
::new(),
763 free_id_outlive
: self.free_id_outlive
,
767 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
768 self.free_substs
.visit_with(visitor
) ||
769 self.implicit_region_bound
.visit_with(visitor
) ||
770 self.caller_bounds
.visit_with(visitor
)
774 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::TypeScheme
<'tcx
> {
775 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
777 generics
: self.generics
.fold_with(folder
),
778 ty
: self.ty
.fold_with(folder
),
782 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
783 self.generics
.visit_with(visitor
) || self.ty
.visit_with(visitor
)