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 middle::subst::{self, VecPerParamSpace};
13 use middle::ty::{self, Lift, TraitRef, Ty};
14 use middle::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: &ty::ctxt<'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: &ty::ctxt<'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, _: &ty::ctxt<'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: &ty::ctxt<'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: &ty::ctxt<'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: &ty::ctxt<'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: &ty::ctxt<'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: &ty::ctxt<'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: &ty::ctxt<'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 folder.enter_region_binder();
194 let result = ty::Binder(self.0.fold_with(folder));
195 folder.exit_region_binder();
199 fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
200 folder.fold_binder(self)
203 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
204 visitor.enter_region_binder();
205 if self.0.visit_with(visitor) { return true }
206 visitor.exit_region_binder();
211 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for P<[T]> {
212 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
213 self.iter().map(|t| t.fold_with(folder)).collect()
216 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
217 self.iter().any(|t| t.visit_with(visitor))
221 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for VecPerParamSpace<T> {
222 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
224 // Things in the Fn space take place under an additional level
225 // of region binding relative to the other spaces. This is
226 // because those entries are attached to a method, and methods
227 // always introduce a level of region binding.
229 let result = self.map_enumerated(|(space, index, elem)| {
230 if space == subst::FnSpace && index == 0 {
231 // enter new level when/if we reach the first thing in fn space
232 folder.enter_region_binder();
234 elem.fold_with(folder)
236 if result.len(subst::FnSpace) > 0 {
237 // if there was anything in fn space, exit the region binding level
238 folder.exit_region_binder();
243 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
244 let mut entered_region_binder = false;
245 let result = self.iter_enumerated().any(|(space, index, t)| {
246 if space == subst::FnSpace && index == 0 {
247 visitor.enter_region_binder();
248 entered_region_binder = true;
250 t.visit_with(visitor)
252 if entered_region_binder {
253 visitor.exit_region_binder();
259 impl<'tcx> TypeFoldable<'tcx> for ty::TraitTy<'tcx> {
260 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
262 principal: self.principal.fold_with(folder),
263 bounds: self.bounds.fold_with(folder),
267 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
268 self.principal.visit_with(visitor) || self.bounds.visit_with(visitor)
272 impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
273 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
274 let sty = match self.sty {
275 ty::TyBox(typ) => ty::TyBox(typ.fold_with(folder)),
276 ty::TyRawPtr(ref tm) => ty::TyRawPtr(tm.fold_with(folder)),
277 ty::TyArray(typ, sz) => ty::TyArray(typ.fold_with(folder), sz),
278 ty::TySlice(typ) => ty::TySlice(typ.fold_with(folder)),
279 ty::TyEnum(tid, ref substs) => {
280 let substs = substs.fold_with(folder);
281 ty::TyEnum(tid, folder.tcx().mk_substs(substs))
283 ty::TyTrait(ref trait_ty) => ty::TyTrait(trait_ty.fold_with(folder)),
284 ty::TyTuple(ref ts) => ty::TyTuple(ts.fold_with(folder)),
285 ty::TyBareFn(opt_def_id, ref f) => {
286 let bfn = f.fold_with(folder);
287 ty::TyBareFn(opt_def_id, folder.tcx().mk_bare_fn(bfn))
289 ty::TyRef(r, ref tm) => {
290 let r = r.fold_with(folder);
291 ty::TyRef(folder.tcx().mk_region(r), tm.fold_with(folder))
293 ty::TyStruct(did, ref substs) => {
294 let substs = substs.fold_with(folder);
295 ty::TyStruct(did, folder.tcx().mk_substs(substs))
297 ty::TyClosure(did, ref substs) => {
298 ty::TyClosure(did, substs.fold_with(folder))
300 ty::TyProjection(ref data) => ty::TyProjection(data.fold_with(folder)),
301 ty::TyBool | ty::TyChar | ty::TyStr | ty::TyInt(_) |
302 ty::TyUint(_) | ty::TyFloat(_) | ty::TyError | ty::TyInfer(_) |
303 ty::TyParam(..) => self.sty.clone(),
305 folder.tcx().mk_ty(sty)
308 fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
309 folder.fold_ty(*self)
312 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
314 ty::TyBox(typ) => typ.visit_with(visitor),
315 ty::TyRawPtr(ref tm) => tm.visit_with(visitor),
316 ty::TyArray(typ, _sz) => typ.visit_with(visitor),
317 ty::TySlice(typ) => typ.visit_with(visitor),
318 ty::TyEnum(_tid, ref substs) => substs.visit_with(visitor),
319 ty::TyTrait(ref trait_ty) => trait_ty.visit_with(visitor),
320 ty::TyTuple(ref ts) => ts.visit_with(visitor),
321 ty::TyBareFn(_opt_def_id, ref f) => f.visit_with(visitor),
322 ty::TyRef(r, ref tm) => r.visit_with(visitor) || tm.visit_with(visitor),
323 ty::TyStruct(_did, ref substs) => substs.visit_with(visitor),
324 ty::TyClosure(_did, ref substs) => substs.visit_with(visitor),
325 ty::TyProjection(ref data) => data.visit_with(visitor),
326 ty::TyBool | ty::TyChar | ty::TyStr | ty::TyInt(_) |
327 ty::TyUint(_) | ty::TyFloat(_) | ty::TyError | ty::TyInfer(_) |
328 ty::TyParam(..) => false,
332 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
333 visitor.visit_ty(self)
337 impl<'tcx> TypeFoldable<'tcx> for ty::BareFnTy<'tcx> {
338 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
339 ty::BareFnTy { sig: self.sig.fold_with(folder),
341 unsafety: self.unsafety }
344 fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
345 folder.fold_bare_fn_ty(self)
348 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
349 self.sig.visit_with(visitor)
353 impl<'tcx> TypeFoldable<'tcx> for ty::ClosureTy<'tcx> {
354 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
356 sig: self.sig.fold_with(folder),
357 unsafety: self.unsafety,
362 fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
363 folder.fold_closure_ty(self)
366 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
367 self.sig.visit_with(visitor)
371 impl<'tcx> TypeFoldable<'tcx> for ty::TypeAndMut<'tcx> {
372 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
373 ty::TypeAndMut { ty: self.ty.fold_with(folder), mutbl: self.mutbl }
376 fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
380 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
381 self.ty.visit_with(visitor)
385 impl<'tcx> TypeFoldable<'tcx> for ty::FnOutput<'tcx> {
386 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
388 ty::FnConverging(ref ty) => ty::FnConverging(ty.fold_with(folder)),
389 ty::FnDiverging => ty::FnDiverging
393 fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
394 folder.fold_output(self)
397 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
399 ty::FnConverging(ref ty) => ty.visit_with(visitor),
400 ty::FnDiverging => false,
405 impl<'tcx> TypeFoldable<'tcx> for ty::FnSig<'tcx> {
406 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
407 ty::FnSig { inputs: self.inputs.fold_with(folder),
408 output: self.output.fold_with(folder),
409 variadic: self.variadic }
412 fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
413 folder.fold_fn_sig(self)
416 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
417 self.inputs.visit_with(visitor) || self.output.visit_with(visitor)
421 impl<'tcx> TypeFoldable<'tcx> for ty::TraitRef<'tcx> {
422 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
423 let substs = self.substs.fold_with(folder);
426 substs: folder.tcx().mk_substs(substs),
430 fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
431 folder.fold_trait_ref(self)
434 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
435 self.substs.visit_with(visitor)
439 impl<'tcx> TypeFoldable<'tcx> for ty::Region {
440 fn super_fold_with<F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> Self {
444 fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
445 folder.fold_region(*self)
448 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
452 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
453 visitor.visit_region(*self)
457 impl<'tcx> TypeFoldable<'tcx> for subst::Substs<'tcx> {
458 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
459 let regions = match self.regions {
460 subst::ErasedRegions => subst::ErasedRegions,
461 subst::NonerasedRegions(ref regions) => {
462 subst::NonerasedRegions(regions.fold_with(folder))
466 subst::Substs { regions: regions,
467 types: self.types.fold_with(folder) }
470 fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
471 folder.fold_substs(self)
474 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
475 self.types.visit_with(visitor) || match self.regions {
476 subst::ErasedRegions => false,
477 subst::NonerasedRegions(ref regions) => regions.visit_with(visitor),
482 impl<'tcx> TypeFoldable<'tcx> for ty::ClosureSubsts<'tcx> {
483 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
484 let func_substs = self.func_substs.fold_with(folder);
486 func_substs: folder.tcx().mk_substs(func_substs),
487 upvar_tys: self.upvar_tys.fold_with(folder),
491 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
492 self.func_substs.visit_with(visitor) || self.upvar_tys.visit_with(visitor)
496 impl<'tcx> TypeFoldable<'tcx> for ty::ItemSubsts<'tcx> {
497 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
499 substs: self.substs.fold_with(folder),
503 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
504 self.substs.visit_with(visitor)
508 impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::AutoRef<'tcx> {
509 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
511 ty::adjustment::AutoPtr(r, m) => {
512 let r = r.fold_with(folder);
513 ty::adjustment::AutoPtr(folder.tcx().mk_region(r), m)
515 ty::adjustment::AutoUnsafe(m) => ty::adjustment::AutoUnsafe(m)
519 fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
520 folder.fold_autoref(self)
523 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
525 ty::adjustment::AutoPtr(r, _m) => r.visit_with(visitor),
526 ty::adjustment::AutoUnsafe(_m) => false,
531 impl<'tcx> TypeFoldable<'tcx> for ty::BuiltinBounds {
532 fn super_fold_with<F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> Self {
536 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
541 impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialBounds<'tcx> {
542 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
543 ty::ExistentialBounds {
544 region_bound: self.region_bound.fold_with(folder),
545 builtin_bounds: self.builtin_bounds,
546 projection_bounds: self.projection_bounds.fold_with(folder),
550 fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
551 folder.fold_existential_bounds(self)
554 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
555 self.region_bound.visit_with(visitor) || self.projection_bounds.visit_with(visitor)
559 impl<'tcx> TypeFoldable<'tcx> for ty::TypeParameterDef<'tcx> {
560 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
561 ty::TypeParameterDef {
566 default: self.default.fold_with(folder),
567 default_def_id: self.default_def_id,
568 object_lifetime_default: self.object_lifetime_default.fold_with(folder),
572 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
573 self.default.visit_with(visitor) ||
574 self.object_lifetime_default.visit_with(visitor)
578 impl<'tcx> TypeFoldable<'tcx> for ty::ObjectLifetimeDefault {
579 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
581 ty::ObjectLifetimeDefault::Ambiguous =>
582 ty::ObjectLifetimeDefault::Ambiguous,
584 ty::ObjectLifetimeDefault::BaseDefault =>
585 ty::ObjectLifetimeDefault::BaseDefault,
587 ty::ObjectLifetimeDefault::Specific(r) =>
588 ty::ObjectLifetimeDefault::Specific(r.fold_with(folder)),
592 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
594 ty::ObjectLifetimeDefault::Specific(r) => r.visit_with(visitor),
600 impl<'tcx> TypeFoldable<'tcx> for ty::RegionParameterDef {
601 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
602 ty::RegionParameterDef {
607 bounds: self.bounds.fold_with(folder)
611 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
612 self.bounds.visit_with(visitor)
616 impl<'tcx> TypeFoldable<'tcx> for ty::Generics<'tcx> {
617 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
619 types: self.types.fold_with(folder),
620 regions: self.regions.fold_with(folder),
624 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
625 self.types.visit_with(visitor) || self.regions.visit_with(visitor)
629 impl<'tcx> TypeFoldable<'tcx> for ty::GenericPredicates<'tcx> {
630 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
631 ty::GenericPredicates {
632 predicates: self.predicates.fold_with(folder),
636 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
637 self.predicates.visit_with(visitor)
641 impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
642 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
644 ty::Predicate::Trait(ref a) =>
645 ty::Predicate::Trait(a.fold_with(folder)),
646 ty::Predicate::Equate(ref binder) =>
647 ty::Predicate::Equate(binder.fold_with(folder)),
648 ty::Predicate::RegionOutlives(ref binder) =>
649 ty::Predicate::RegionOutlives(binder.fold_with(folder)),
650 ty::Predicate::TypeOutlives(ref binder) =>
651 ty::Predicate::TypeOutlives(binder.fold_with(folder)),
652 ty::Predicate::Projection(ref binder) =>
653 ty::Predicate::Projection(binder.fold_with(folder)),
654 ty::Predicate::WellFormed(data) =>
655 ty::Predicate::WellFormed(data.fold_with(folder)),
656 ty::Predicate::ObjectSafe(trait_def_id) =>
657 ty::Predicate::ObjectSafe(trait_def_id),
661 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
663 ty::Predicate::Trait(ref a) => a.visit_with(visitor),
664 ty::Predicate::Equate(ref binder) => binder.visit_with(visitor),
665 ty::Predicate::RegionOutlives(ref binder) => binder.visit_with(visitor),
666 ty::Predicate::TypeOutlives(ref binder) => binder.visit_with(visitor),
667 ty::Predicate::Projection(ref binder) => binder.visit_with(visitor),
668 ty::Predicate::WellFormed(data) => data.visit_with(visitor),
669 ty::Predicate::ObjectSafe(_trait_def_id) => false,
674 impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionPredicate<'tcx> {
675 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
676 ty::ProjectionPredicate {
677 projection_ty: self.projection_ty.fold_with(folder),
678 ty: self.ty.fold_with(folder),
682 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
683 self.projection_ty.visit_with(visitor) || self.ty.visit_with(visitor)
687 impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionTy<'tcx> {
688 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
690 trait_ref: self.trait_ref.fold_with(folder),
691 item_name: self.item_name,
695 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
696 self.trait_ref.visit_with(visitor)
700 impl<'tcx> TypeFoldable<'tcx> for ty::InstantiatedPredicates<'tcx> {
701 fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
702 ty::InstantiatedPredicates {
703 predicates: self.predicates.fold_with(folder),
707 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
708 self.predicates.visit_with(visitor)
712 impl<'tcx> TypeFoldable<'tcx> for ty::EquatePredicate<'tcx> {
713 fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
714 ty::EquatePredicate(self.0.fold_with(folder),
715 self.1.fold_with(folder))
718 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
719 self.0.visit_with(visitor) || self.1.visit_with(visitor)
723 impl<'tcx> TypeFoldable<'tcx> for ty::TraitPredicate<'tcx> {
724 fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
726 trait_ref: self.trait_ref.fold_with(folder)
730 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
731 self.trait_ref.visit_with(visitor)
735 impl<'tcx,T,U> TypeFoldable<'tcx> for ty::OutlivesPredicate<T,U>
736 where T : TypeFoldable<'tcx>,
737 U : TypeFoldable<'tcx>,
739 fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
740 ty::OutlivesPredicate(self.0.fold_with(folder),
741 self.1.fold_with(folder))
744 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
745 self.0.visit_with(visitor) || self.1.visit_with(visitor)
749 impl<'tcx> TypeFoldable<'tcx> for ty::ClosureUpvar<'tcx> {
750 fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
754 ty: self.ty.fold_with(folder),
758 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
759 self.ty.visit_with(visitor)
763 impl<'a, 'tcx> TypeFoldable<'tcx> for ty::ParameterEnvironment<'a, 'tcx> where 'tcx: 'a {
764 fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
765 ty::ParameterEnvironment {
767 free_substs: self.free_substs.fold_with(folder),
768 implicit_region_bound: self.implicit_region_bound.fold_with(folder),
769 caller_bounds: self.caller_bounds.fold_with(folder),
770 selection_cache: traits::SelectionCache::new(),
771 evaluation_cache: traits::EvaluationCache::new(),
772 free_id_outlive: self.free_id_outlive,
776 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
777 self.free_substs.visit_with(visitor) ||
778 self.implicit_region_bound.visit_with(visitor) ||
779 self.caller_bounds.visit_with(visitor)
783 impl<'tcx> TypeFoldable<'tcx> for ty::TypeScheme<'tcx> {
784 fn super_fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
786 generics: self.generics.fold_with(folder),
787 ty: self.ty.fold_with(folder),
791 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
792 self.generics.visit_with(visitor) || self.ty.visit_with(visitor)