]> git.lizzy.rs Git - rust.git/blob - src/librustc/ty/structural_impls.rs
28184725b1c81bdf333953a239936fd53b8742d0
[rust.git] / src / librustc / ty / structural_impls.rs
1 //! This module contains implements of the `Lift` and `TypeFoldable`
2 //! traits for various types in the Rust compiler. Most are written by
3 //! hand, though we've recently added some macros (e.g.,
4 //! `BraceStructLiftImpl!`) to help with the tedium.
5
6 use mir::ProjectionKind;
7 use mir::interpret::ConstValue;
8 use ty::{self, Lift, Ty, TyCtxt};
9 use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
10 use rustc_data_structures::indexed_vec::{IndexVec, Idx};
11 use smallvec::SmallVec;
12 use mir::interpret;
13
14 use std::rc::Rc;
15
16 ///////////////////////////////////////////////////////////////////////////
17 // Atomic structs
18 //
19 // For things that don't carry any arena-allocated data (and are
20 // copy...), just add them to this list.
21
22 CloneTypeFoldableAndLiftImpls! {
23     (),
24     bool,
25     usize,
26     ::ty::layout::VariantIdx,
27     u64,
28     String,
29     ::middle::region::Scope,
30     ::syntax::ast::FloatTy,
31     ::syntax::ast::NodeId,
32     ::syntax_pos::symbol::Symbol,
33     ::hir::def::Def,
34     ::hir::def_id::DefId,
35     ::hir::InlineAsm,
36     ::hir::MatchSource,
37     ::hir::Mutability,
38     ::hir::Unsafety,
39     ::rustc_target::spec::abi::Abi,
40     ::mir::Local,
41     ::mir::Promoted,
42     ::traits::Reveal,
43     ::ty::adjustment::AutoBorrowMutability,
44     ::ty::AdtKind,
45     // Including `BoundRegion` is a *bit* dubious, but direct
46     // references to bound region appear in `ty::Error`, and aren't
47     // really meant to be folded. In general, we can only fold a fully
48     // general `Region`.
49     ::ty::BoundRegion,
50     ::ty::ClosureKind,
51     ::ty::IntVarValue,
52     ::ty::ParamTy,
53     ::ty::UniverseIndex,
54     ::ty::Variance,
55     ::syntax_pos::Span,
56     ConstValue<'tcx>,
57 }
58
59 ///////////////////////////////////////////////////////////////////////////
60 // Lift implementations
61
62 impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>> Lift<'tcx> for (A, B) {
63     type Lifted = (A::Lifted, B::Lifted);
64     fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
65         tcx.lift(&self.0).and_then(|a| tcx.lift(&self.1).map(|b| (a, b)))
66     }
67 }
68
69 impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>, C: Lift<'tcx>> Lift<'tcx> for (A, B, C) {
70     type Lifted = (A::Lifted, B::Lifted, C::Lifted);
71     fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
72         tcx.lift(&self.0).and_then(|a| {
73             tcx.lift(&self.1).and_then(|b| tcx.lift(&self.2).map(|c| (a, b, c)))
74         })
75     }
76 }
77
78 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
79     type Lifted = Option<T::Lifted>;
80     fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
81         match *self {
82             Some(ref x) => tcx.lift(x).map(Some),
83             None => Some(None)
84         }
85     }
86 }
87
88 impl<'tcx, T: Lift<'tcx>, E: Lift<'tcx>> Lift<'tcx> for Result<T, E> {
89     type Lifted = Result<T::Lifted, E::Lifted>;
90     fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
91         match *self {
92             Ok(ref x) => tcx.lift(x).map(Ok),
93             Err(ref e) => tcx.lift(e).map(Err)
94         }
95     }
96 }
97
98 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Box<T> {
99     type Lifted = Box<T::Lifted>;
100     fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
101         tcx.lift(&**self).map(Box::new)
102     }
103 }
104
105 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for [T] {
106     type Lifted = Vec<T::Lifted>;
107     fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
108         // type annotation needed to inform `projection_must_outlive`
109         let mut result : Vec<<T as Lift<'tcx>>::Lifted>
110             = Vec::with_capacity(self.len());
111         for x in self {
112             if let Some(value) = tcx.lift(x) {
113                 result.push(value);
114             } else {
115                 return None;
116             }
117         }
118         Some(result)
119     }
120 }
121
122 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Vec<T> {
123     type Lifted = Vec<T::Lifted>;
124     fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
125         tcx.lift(&self[..])
126     }
127 }
128
129 impl<'tcx, I: Idx, T: Lift<'tcx>> Lift<'tcx> for IndexVec<I, T> {
130     type Lifted = IndexVec<I, T::Lifted>;
131     fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
132         self.iter()
133             .map(|e| tcx.lift(e))
134             .collect()
135     }
136 }
137
138 impl<'a, 'tcx> Lift<'tcx> for ty::TraitRef<'a> {
139     type Lifted = ty::TraitRef<'tcx>;
140     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
141         tcx.lift(&self.substs).map(|substs| ty::TraitRef {
142             def_id: self.def_id,
143             substs,
144         })
145     }
146 }
147
148 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialTraitRef<'a> {
149     type Lifted = ty::ExistentialTraitRef<'tcx>;
150     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
151         tcx.lift(&self.substs).map(|substs| ty::ExistentialTraitRef {
152             def_id: self.def_id,
153             substs,
154         })
155     }
156 }
157
158 impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> {
159     type Lifted = ty::TraitPredicate<'tcx>;
160     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
161                              -> Option<ty::TraitPredicate<'tcx>> {
162         tcx.lift(&self.trait_ref).map(|trait_ref| ty::TraitPredicate {
163             trait_ref,
164         })
165     }
166 }
167
168 impl<'a, 'tcx> Lift<'tcx> for ty::SubtypePredicate<'a> {
169     type Lifted = ty::SubtypePredicate<'tcx>;
170     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
171                              -> Option<ty::SubtypePredicate<'tcx>> {
172         tcx.lift(&(self.a, self.b)).map(|(a, b)| ty::SubtypePredicate {
173             a_is_expected: self.a_is_expected,
174             a,
175             b,
176         })
177     }
178 }
179
180 impl<'tcx, A: Copy+Lift<'tcx>, B: Copy+Lift<'tcx>> Lift<'tcx> for ty::OutlivesPredicate<A, B> {
181     type Lifted = ty::OutlivesPredicate<A::Lifted, B::Lifted>;
182     fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
183         tcx.lift(&(self.0, self.1)).map(|(a, b)| ty::OutlivesPredicate(a, b))
184     }
185 }
186
187 impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionTy<'a> {
188     type Lifted = ty::ProjectionTy<'tcx>;
189     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
190                              -> Option<ty::ProjectionTy<'tcx>> {
191         tcx.lift(&self.substs).map(|substs| {
192             ty::ProjectionTy {
193                 item_def_id: self.item_def_id,
194                 substs,
195             }
196         })
197     }
198 }
199
200 impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionPredicate<'a> {
201     type Lifted = ty::ProjectionPredicate<'tcx>;
202     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
203                              -> Option<ty::ProjectionPredicate<'tcx>> {
204         tcx.lift(&(self.projection_ty, self.ty)).map(|(projection_ty, ty)| {
205             ty::ProjectionPredicate {
206                 projection_ty,
207                 ty,
208             }
209         })
210     }
211 }
212
213 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> {
214     type Lifted = ty::ExistentialProjection<'tcx>;
215     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
216         tcx.lift(&self.substs).map(|substs| {
217             ty::ExistentialProjection {
218                 substs,
219                 ty: tcx.lift(&self.ty).expect("type must lift when substs do"),
220                 item_def_id: self.item_def_id,
221             }
222         })
223     }
224 }
225
226 impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> {
227     type Lifted = ty::Predicate<'tcx>;
228     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
229         match *self {
230             ty::Predicate::Trait(ref binder) => {
231                 tcx.lift(binder).map(ty::Predicate::Trait)
232             }
233             ty::Predicate::Subtype(ref binder) => {
234                 tcx.lift(binder).map(ty::Predicate::Subtype)
235             }
236             ty::Predicate::RegionOutlives(ref binder) => {
237                 tcx.lift(binder).map(ty::Predicate::RegionOutlives)
238             }
239             ty::Predicate::TypeOutlives(ref binder) => {
240                 tcx.lift(binder).map(ty::Predicate::TypeOutlives)
241             }
242             ty::Predicate::Projection(ref binder) => {
243                 tcx.lift(binder).map(ty::Predicate::Projection)
244             }
245             ty::Predicate::WellFormed(ty) => {
246                 tcx.lift(&ty).map(ty::Predicate::WellFormed)
247             }
248             ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
249                 tcx.lift(&closure_substs)
250                    .map(|closure_substs| ty::Predicate::ClosureKind(closure_def_id,
251                                                                     closure_substs,
252                                                                     kind))
253             }
254             ty::Predicate::ObjectSafe(trait_def_id) => {
255                 Some(ty::Predicate::ObjectSafe(trait_def_id))
256             }
257             ty::Predicate::ConstEvaluatable(def_id, substs) => {
258                 tcx.lift(&substs).map(|substs| {
259                     ty::Predicate::ConstEvaluatable(def_id, substs)
260                 })
261             }
262         }
263     }
264 }
265
266 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<T> {
267     type Lifted = ty::Binder<T::Lifted>;
268     fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
269         tcx.lift(self.skip_binder()).map(ty::Binder::bind)
270     }
271 }
272
273 impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> {
274     type Lifted = ty::ParamEnv<'tcx>;
275     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
276         tcx.lift(&self.caller_bounds).map(|caller_bounds| {
277             ty::ParamEnv {
278                 reveal: self.reveal,
279                 caller_bounds,
280                 def_id: self.def_id,
281             }
282         })
283     }
284 }
285
286 impl<'a, 'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::ParamEnvAnd<'a, T> {
287     type Lifted = ty::ParamEnvAnd<'tcx, T::Lifted>;
288     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
289         tcx.lift(&self.param_env).and_then(|param_env| {
290             tcx.lift(&self.value).map(|value| {
291                 ty::ParamEnvAnd {
292                     param_env,
293                     value,
294                 }
295             })
296         })
297     }
298 }
299
300 impl<'a, 'tcx> Lift<'tcx> for ty::ClosureSubsts<'a> {
301     type Lifted = ty::ClosureSubsts<'tcx>;
302     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
303         tcx.lift(&self.substs).map(|substs| {
304             ty::ClosureSubsts { substs }
305         })
306     }
307 }
308
309 impl<'a, 'tcx> Lift<'tcx> for ty::GeneratorSubsts<'a> {
310     type Lifted = ty::GeneratorSubsts<'tcx>;
311     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
312         tcx.lift(&self.substs).map(|substs| {
313             ty::GeneratorSubsts { substs }
314         })
315     }
316 }
317
318 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjustment<'a> {
319     type Lifted = ty::adjustment::Adjustment<'tcx>;
320     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
321         tcx.lift(&self.kind).and_then(|kind| {
322             tcx.lift(&self.target).map(|target| {
323                 ty::adjustment::Adjustment { kind, target }
324             })
325         })
326     }
327 }
328
329 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
330     type Lifted = ty::adjustment::Adjust<'tcx>;
331     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
332         match *self {
333             ty::adjustment::Adjust::NeverToAny =>
334                 Some(ty::adjustment::Adjust::NeverToAny),
335             ty::adjustment::Adjust::ReifyFnPointer =>
336                 Some(ty::adjustment::Adjust::ReifyFnPointer),
337             ty::adjustment::Adjust::UnsafeFnPointer =>
338                 Some(ty::adjustment::Adjust::UnsafeFnPointer),
339             ty::adjustment::Adjust::ClosureFnPointer =>
340                 Some(ty::adjustment::Adjust::ClosureFnPointer),
341             ty::adjustment::Adjust::MutToConstPointer =>
342                 Some(ty::adjustment::Adjust::MutToConstPointer),
343             ty::adjustment::Adjust::Unsize =>
344                 Some(ty::adjustment::Adjust::Unsize),
345             ty::adjustment::Adjust::Deref(ref overloaded) => {
346                 tcx.lift(overloaded).map(ty::adjustment::Adjust::Deref)
347             }
348             ty::adjustment::Adjust::Borrow(ref autoref) => {
349                 tcx.lift(autoref).map(ty::adjustment::Adjust::Borrow)
350             }
351         }
352     }
353 }
354
355 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::OverloadedDeref<'a> {
356     type Lifted = ty::adjustment::OverloadedDeref<'tcx>;
357     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
358         tcx.lift(&self.region).map(|region| {
359             ty::adjustment::OverloadedDeref {
360                 region,
361                 mutbl: self.mutbl,
362             }
363         })
364     }
365 }
366
367 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
368     type Lifted = ty::adjustment::AutoBorrow<'tcx>;
369     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
370         match *self {
371             ty::adjustment::AutoBorrow::Ref(r, m) => {
372                 tcx.lift(&r).map(|r| ty::adjustment::AutoBorrow::Ref(r, m))
373             }
374             ty::adjustment::AutoBorrow::RawPtr(m) => {
375                 Some(ty::adjustment::AutoBorrow::RawPtr(m))
376             }
377         }
378     }
379 }
380
381 impl<'a, 'tcx> Lift<'tcx> for ty::GenSig<'a> {
382     type Lifted = ty::GenSig<'tcx>;
383     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
384         tcx.lift(&(self.yield_ty, self.return_ty))
385            .map(|(yield_ty, return_ty)| {
386                ty::GenSig {
387                    yield_ty,
388                    return_ty,
389                }
390            })
391     }
392 }
393
394 impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> {
395     type Lifted = ty::FnSig<'tcx>;
396     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
397         tcx.lift(&self.inputs_and_output).map(|x| {
398             ty::FnSig {
399                 inputs_and_output: x,
400                 variadic: self.variadic,
401                 unsafety: self.unsafety,
402                 abi: self.abi,
403             }
404         })
405     }
406 }
407
408 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::error::ExpectedFound<T> {
409     type Lifted = ty::error::ExpectedFound<T::Lifted>;
410     fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
411         tcx.lift(&self.expected).and_then(|expected| {
412             tcx.lift(&self.found).map(|found| {
413                 ty::error::ExpectedFound {
414                     expected,
415                     found,
416                 }
417             })
418         })
419     }
420 }
421
422 impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
423     type Lifted = ty::error::TypeError<'tcx>;
424     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
425         use ty::error::TypeError::*;
426
427         Some(match *self {
428             Mismatch => Mismatch,
429             UnsafetyMismatch(x) => UnsafetyMismatch(x),
430             AbiMismatch(x) => AbiMismatch(x),
431             Mutability => Mutability,
432             TupleSize(x) => TupleSize(x),
433             FixedArraySize(x) => FixedArraySize(x),
434             ArgCount => ArgCount,
435             RegionsDoesNotOutlive(a, b) => {
436                 return tcx.lift(&(a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b))
437             }
438             RegionsInsufficientlyPolymorphic(a, b) => {
439                 return tcx.lift(&b).map(|b| RegionsInsufficientlyPolymorphic(a, b))
440             }
441             RegionsOverlyPolymorphic(a, b) => {
442                 return tcx.lift(&b).map(|b| RegionsOverlyPolymorphic(a, b))
443             }
444             IntMismatch(x) => IntMismatch(x),
445             FloatMismatch(x) => FloatMismatch(x),
446             Traits(x) => Traits(x),
447             VariadicMismatch(x) => VariadicMismatch(x),
448             CyclicTy(t) => return tcx.lift(&t).map(|t| CyclicTy(t)),
449             ProjectionMismatched(x) => ProjectionMismatched(x),
450             ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
451             Sorts(ref x) => return tcx.lift(x).map(Sorts),
452             ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch)
453         })
454     }
455 }
456
457 impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
458     type Lifted = ty::InstanceDef<'tcx>;
459     fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
460         match *self {
461             ty::InstanceDef::Item(def_id) =>
462                 Some(ty::InstanceDef::Item(def_id)),
463             ty::InstanceDef::VtableShim(def_id) =>
464                 Some(ty::InstanceDef::VtableShim(def_id)),
465             ty::InstanceDef::Intrinsic(def_id) =>
466                 Some(ty::InstanceDef::Intrinsic(def_id)),
467             ty::InstanceDef::FnPtrShim(def_id, ref ty) =>
468                 Some(ty::InstanceDef::FnPtrShim(def_id, tcx.lift(ty)?)),
469             ty::InstanceDef::Virtual(def_id, n) =>
470                 Some(ty::InstanceDef::Virtual(def_id, n)),
471             ty::InstanceDef::ClosureOnceShim { call_once } =>
472                 Some(ty::InstanceDef::ClosureOnceShim { call_once }),
473             ty::InstanceDef::DropGlue(def_id, ref ty) =>
474                 Some(ty::InstanceDef::DropGlue(def_id, tcx.lift(ty)?)),
475             ty::InstanceDef::CloneShim(def_id, ref ty) =>
476                 Some(ty::InstanceDef::CloneShim(def_id, tcx.lift(ty)?)),
477         }
478     }
479 }
480
481 BraceStructLiftImpl! {
482     impl<'a, 'tcx> Lift<'tcx> for ty::Instance<'a> {
483         type Lifted = ty::Instance<'tcx>;
484         def, substs
485     }
486 }
487
488 BraceStructLiftImpl! {
489     impl<'a, 'tcx> Lift<'tcx> for interpret::GlobalId<'a> {
490         type Lifted = interpret::GlobalId<'tcx>;
491         instance, promoted
492     }
493 }
494
495 ///////////////////////////////////////////////////////////////////////////
496 // TypeFoldable implementations.
497 //
498 // Ideally, each type should invoke `folder.fold_foo(self)` and
499 // nothing else. In some cases, though, we haven't gotten around to
500 // adding methods on the `folder` yet, and thus the folding is
501 // hard-coded here. This is less-flexible, because folders cannot
502 // override the behavior, but there are a lot of random types and one
503 // can easily refactor the folding into the TypeFolder trait as
504 // needed.
505
506 /// AdtDefs are basically the same as a DefId.
507 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::AdtDef {
508     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _folder: &mut F) -> Self {
509         *self
510     }
511
512     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
513         false
514     }
515 }
516
517 impl<'tcx, T:TypeFoldable<'tcx>, U:TypeFoldable<'tcx>> TypeFoldable<'tcx> for (T, U) {
518     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> (T, U) {
519         (self.0.fold_with(folder), self.1.fold_with(folder))
520     }
521
522     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
523         self.0.visit_with(visitor) || self.1.visit_with(visitor)
524     }
525 }
526
527 EnumTypeFoldableImpl! {
528     impl<'tcx, T> TypeFoldable<'tcx> for Option<T> {
529         (Some)(a),
530         (None),
531     } where T: TypeFoldable<'tcx>
532 }
533
534 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
535     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
536         Rc::new((**self).fold_with(folder))
537     }
538
539     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
540         (**self).visit_with(visitor)
541     }
542 }
543
544 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> {
545     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
546         let content: T = (**self).fold_with(folder);
547         box content
548     }
549
550     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
551         (**self).visit_with(visitor)
552     }
553 }
554
555 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
556     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
557         self.iter().map(|t| t.fold_with(folder)).collect()
558     }
559
560     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
561         self.iter().any(|t| t.visit_with(visitor))
562     }
563 }
564
565 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> {
566     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
567         self.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>().into_boxed_slice()
568     }
569
570     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
571         self.iter().any(|t| t.visit_with(visitor))
572     }
573 }
574
575 impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
576     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
577         self.map_bound_ref(|ty| ty.fold_with(folder))
578     }
579
580     fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
581         folder.fold_binder(self)
582     }
583
584     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
585         self.skip_binder().visit_with(visitor)
586     }
587
588     fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
589         visitor.visit_binder(self)
590     }
591 }
592
593 BraceStructTypeFoldableImpl! {
594     impl<'tcx> TypeFoldable<'tcx> for ty::ParamEnv<'tcx> { reveal, caller_bounds, def_id }
595 }
596
597 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {
598     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
599         let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
600         folder.tcx().intern_existential_predicates(&v)
601     }
602
603     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
604         self.iter().any(|p| p.visit_with(visitor))
605     }
606 }
607
608 EnumTypeFoldableImpl! {
609     impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialPredicate<'tcx> {
610         (ty::ExistentialPredicate::Trait)(a),
611         (ty::ExistentialPredicate::Projection)(a),
612         (ty::ExistentialPredicate::AutoTrait)(a),
613     }
614 }
615
616 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
617     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
618         let v = self.iter().map(|t| t.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
619         folder.tcx().intern_type_list(&v)
620     }
621
622     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
623         self.iter().any(|t| t.visit_with(visitor))
624     }
625 }
626
627 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind<'tcx>> {
628     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
629         let v = self.iter().map(|t| t.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
630         folder.tcx().intern_projs(&v)
631     }
632
633     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
634         self.iter().any(|t| t.visit_with(visitor))
635     }
636 }
637
638 impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
639     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
640         use ty::InstanceDef::*;
641         Self {
642             substs: self.substs.fold_with(folder),
643             def: match self.def {
644                 Item(did) => Item(did.fold_with(folder)),
645                 VtableShim(did) => VtableShim(did.fold_with(folder)),
646                 Intrinsic(did) => Intrinsic(did.fold_with(folder)),
647                 FnPtrShim(did, ty) => FnPtrShim(
648                     did.fold_with(folder),
649                     ty.fold_with(folder),
650                 ),
651                 Virtual(did, i) => Virtual(
652                     did.fold_with(folder),
653                     i,
654                 ),
655                 ClosureOnceShim { call_once } => ClosureOnceShim {
656                     call_once: call_once.fold_with(folder),
657                 },
658                 DropGlue(did, ty) => DropGlue(
659                     did.fold_with(folder),
660                     ty.fold_with(folder),
661                 ),
662                 CloneShim(did, ty) => CloneShim(
663                     did.fold_with(folder),
664                     ty.fold_with(folder),
665                 ),
666             },
667         }
668     }
669
670     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
671         use ty::InstanceDef::*;
672         self.substs.visit_with(visitor) ||
673         match self.def {
674             Item(did) | VtableShim(did) | Intrinsic(did) | Virtual(did, _) => {
675                 did.visit_with(visitor)
676             },
677             FnPtrShim(did, ty) | CloneShim(did, ty) => {
678                 did.visit_with(visitor) || ty.visit_with(visitor)
679             },
680             DropGlue(did, ty) => {
681                 did.visit_with(visitor) || ty.visit_with(visitor)
682             },
683             ClosureOnceShim { call_once } => call_once.visit_with(visitor),
684         }
685     }
686 }
687
688 impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'tcx> {
689     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
690         Self {
691             instance: self.instance.fold_with(folder),
692             promoted: self.promoted
693         }
694     }
695
696     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
697         self.instance.visit_with(visitor)
698     }
699 }
700
701 impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
702     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
703         let sty = match self.sty {
704             ty::RawPtr(tm) => ty::RawPtr(tm.fold_with(folder)),
705             ty::Array(typ, sz) => ty::Array(typ.fold_with(folder), sz.fold_with(folder)),
706             ty::Slice(typ) => ty::Slice(typ.fold_with(folder)),
707             ty::Adt(tid, substs) => ty::Adt(tid, substs.fold_with(folder)),
708             ty::Dynamic(ref trait_ty, ref region) =>
709                 ty::Dynamic(trait_ty.fold_with(folder), region.fold_with(folder)),
710             ty::Tuple(ts) => ty::Tuple(ts.fold_with(folder)),
711             ty::FnDef(def_id, substs) => {
712                 ty::FnDef(def_id, substs.fold_with(folder))
713             }
714             ty::FnPtr(f) => ty::FnPtr(f.fold_with(folder)),
715             ty::Ref(ref r, ty, mutbl) => {
716                 ty::Ref(r.fold_with(folder), ty.fold_with(folder), mutbl)
717             }
718             ty::Generator(did, substs, movability) => {
719                 ty::Generator(
720                     did,
721                     substs.fold_with(folder),
722                     movability)
723             }
724             ty::GeneratorWitness(types) => ty::GeneratorWitness(types.fold_with(folder)),
725             ty::Closure(did, substs) => ty::Closure(did, substs.fold_with(folder)),
726             ty::Projection(ref data) => ty::Projection(data.fold_with(folder)),
727             ty::UnnormalizedProjection(ref data) => {
728                 ty::UnnormalizedProjection(data.fold_with(folder))
729             }
730             ty::Opaque(did, substs) => ty::Opaque(did, substs.fold_with(folder)),
731
732             ty::Bool |
733             ty::Char |
734             ty::Str |
735             ty::Int(_) |
736             ty::Uint(_) |
737             ty::Float(_) |
738             ty::Error |
739             ty::Infer(_) |
740             ty::Param(..) |
741             ty::Bound(..) |
742             ty::Placeholder(..) |
743             ty::Never |
744             ty::Foreign(..) => return self
745         };
746
747         if self.sty == sty {
748             self
749         } else {
750             folder.tcx().mk_ty(sty)
751         }
752     }
753
754     fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
755         folder.fold_ty(*self)
756     }
757
758     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
759         match self.sty {
760             ty::RawPtr(ref tm) => tm.visit_with(visitor),
761             ty::Array(typ, sz) => typ.visit_with(visitor) || sz.visit_with(visitor),
762             ty::Slice(typ) => typ.visit_with(visitor),
763             ty::Adt(_, substs) => substs.visit_with(visitor),
764             ty::Dynamic(ref trait_ty, ref reg) =>
765                 trait_ty.visit_with(visitor) || reg.visit_with(visitor),
766             ty::Tuple(ts) => ts.visit_with(visitor),
767             ty::FnDef(_, substs) => substs.visit_with(visitor),
768             ty::FnPtr(ref f) => f.visit_with(visitor),
769             ty::Ref(r, ty, _) => r.visit_with(visitor) || ty.visit_with(visitor),
770             ty::Generator(_did, ref substs, _) => {
771                 substs.visit_with(visitor)
772             }
773             ty::GeneratorWitness(ref types) => types.visit_with(visitor),
774             ty::Closure(_did, ref substs) => substs.visit_with(visitor),
775             ty::Projection(ref data) | ty::UnnormalizedProjection(ref data) => {
776                 data.visit_with(visitor)
777             }
778             ty::Opaque(_, ref substs) => substs.visit_with(visitor),
779
780             ty::Bool |
781             ty::Char |
782             ty::Str |
783             ty::Int(_) |
784             ty::Uint(_) |
785             ty::Float(_) |
786             ty::Error |
787             ty::Infer(_) |
788             ty::Bound(..) |
789             ty::Placeholder(..) |
790             ty::Param(..) |
791             ty::Never |
792             ty::Foreign(..) => false,
793         }
794     }
795
796     fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
797         visitor.visit_ty(self)
798     }
799 }
800
801 BraceStructTypeFoldableImpl! {
802     impl<'tcx> TypeFoldable<'tcx> for ty::TypeAndMut<'tcx> {
803         ty, mutbl
804     }
805 }
806
807 BraceStructTypeFoldableImpl! {
808     impl<'tcx> TypeFoldable<'tcx> for ty::GenSig<'tcx> {
809         yield_ty, return_ty
810     }
811 }
812
813 BraceStructTypeFoldableImpl! {
814     impl<'tcx> TypeFoldable<'tcx> for ty::FnSig<'tcx> {
815         inputs_and_output, variadic, unsafety, abi
816     }
817 }
818
819 BraceStructTypeFoldableImpl! {
820     impl<'tcx> TypeFoldable<'tcx> for ty::TraitRef<'tcx> { def_id, substs }
821 }
822
823 BraceStructTypeFoldableImpl! {
824     impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialTraitRef<'tcx> { def_id, substs }
825 }
826
827 BraceStructTypeFoldableImpl! {
828     impl<'tcx> TypeFoldable<'tcx> for ty::ImplHeader<'tcx> {
829         impl_def_id,
830         self_ty,
831         trait_ref,
832         predicates,
833     }
834 }
835
836 impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
837     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _folder: &mut F) -> Self {
838         *self
839     }
840
841     fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
842         folder.fold_region(*self)
843     }
844
845     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
846         false
847     }
848
849     fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
850         visitor.visit_region(*self)
851     }
852 }
853
854 BraceStructTypeFoldableImpl! {
855     impl<'tcx> TypeFoldable<'tcx> for ty::ClosureSubsts<'tcx> {
856         substs,
857     }
858 }
859
860 BraceStructTypeFoldableImpl! {
861     impl<'tcx> TypeFoldable<'tcx> for ty::GeneratorSubsts<'tcx> {
862         substs,
863     }
864 }
865
866 BraceStructTypeFoldableImpl! {
867     impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::Adjustment<'tcx> {
868         kind,
869         target,
870     }
871 }
872
873 EnumTypeFoldableImpl! {
874     impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::Adjust<'tcx> {
875         (ty::adjustment::Adjust::NeverToAny),
876         (ty::adjustment::Adjust::ReifyFnPointer),
877         (ty::adjustment::Adjust::UnsafeFnPointer),
878         (ty::adjustment::Adjust::ClosureFnPointer),
879         (ty::adjustment::Adjust::MutToConstPointer),
880         (ty::adjustment::Adjust::Unsize),
881         (ty::adjustment::Adjust::Deref)(a),
882         (ty::adjustment::Adjust::Borrow)(a),
883     }
884 }
885
886 BraceStructTypeFoldableImpl! {
887     impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::OverloadedDeref<'tcx> {
888         region, mutbl,
889     }
890 }
891
892 EnumTypeFoldableImpl! {
893     impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::AutoBorrow<'tcx> {
894         (ty::adjustment::AutoBorrow::Ref)(a, b),
895         (ty::adjustment::AutoBorrow::RawPtr)(m),
896     }
897 }
898
899 BraceStructTypeFoldableImpl! {
900     impl<'tcx> TypeFoldable<'tcx> for ty::GenericPredicates<'tcx> {
901         parent, predicates
902     }
903 }
904
905 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
906     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
907         let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
908         folder.tcx().intern_predicates(&v)
909     }
910
911     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
912         self.iter().any(|p| p.visit_with(visitor))
913     }
914 }
915
916 EnumTypeFoldableImpl! {
917     impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
918         (ty::Predicate::Trait)(a),
919         (ty::Predicate::Subtype)(a),
920         (ty::Predicate::RegionOutlives)(a),
921         (ty::Predicate::TypeOutlives)(a),
922         (ty::Predicate::Projection)(a),
923         (ty::Predicate::WellFormed)(a),
924         (ty::Predicate::ClosureKind)(a, b, c),
925         (ty::Predicate::ObjectSafe)(a),
926         (ty::Predicate::ConstEvaluatable)(a, b),
927     }
928 }
929
930 BraceStructTypeFoldableImpl! {
931     impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionPredicate<'tcx> {
932         projection_ty, ty
933     }
934 }
935
936 BraceStructTypeFoldableImpl! {
937     impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialProjection<'tcx> {
938         ty, substs, item_def_id
939     }
940 }
941
942 BraceStructTypeFoldableImpl! {
943     impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionTy<'tcx> {
944         substs, item_def_id
945     }
946 }
947
948 BraceStructTypeFoldableImpl! {
949     impl<'tcx> TypeFoldable<'tcx> for ty::InstantiatedPredicates<'tcx> {
950         predicates
951     }
952 }
953
954 BraceStructTypeFoldableImpl! {
955     impl<'tcx, T> TypeFoldable<'tcx> for ty::ParamEnvAnd<'tcx, T> {
956         param_env, value
957     } where T: TypeFoldable<'tcx>
958 }
959
960 BraceStructTypeFoldableImpl! {
961     impl<'tcx> TypeFoldable<'tcx> for ty::SubtypePredicate<'tcx> {
962         a_is_expected, a, b
963     }
964 }
965
966 BraceStructTypeFoldableImpl! {
967     impl<'tcx> TypeFoldable<'tcx> for ty::TraitPredicate<'tcx> {
968         trait_ref
969     }
970 }
971
972 TupleStructTypeFoldableImpl! {
973     impl<'tcx,T,U> TypeFoldable<'tcx> for ty::OutlivesPredicate<T,U> {
974         a, b
975     } where T : TypeFoldable<'tcx>, U : TypeFoldable<'tcx>,
976 }
977
978 BraceStructTypeFoldableImpl! {
979     impl<'tcx> TypeFoldable<'tcx> for ty::ClosureUpvar<'tcx> {
980         def, span, ty
981     }
982 }
983
984 BraceStructTypeFoldableImpl! {
985     impl<'tcx, T> TypeFoldable<'tcx> for ty::error::ExpectedFound<T> {
986         expected, found
987     } where T: TypeFoldable<'tcx>
988 }
989
990 impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T> {
991     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
992         self.iter().map(|x| x.fold_with(folder)).collect()
993     }
994
995     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
996         self.iter().any(|t| t.visit_with(visitor))
997     }
998 }
999
1000 EnumTypeFoldableImpl! {
1001     impl<'tcx> TypeFoldable<'tcx> for ty::error::TypeError<'tcx> {
1002         (ty::error::TypeError::Mismatch),
1003         (ty::error::TypeError::UnsafetyMismatch)(x),
1004         (ty::error::TypeError::AbiMismatch)(x),
1005         (ty::error::TypeError::Mutability),
1006         (ty::error::TypeError::TupleSize)(x),
1007         (ty::error::TypeError::FixedArraySize)(x),
1008         (ty::error::TypeError::ArgCount),
1009         (ty::error::TypeError::RegionsDoesNotOutlive)(a, b),
1010         (ty::error::TypeError::RegionsInsufficientlyPolymorphic)(a, b),
1011         (ty::error::TypeError::RegionsOverlyPolymorphic)(a, b),
1012         (ty::error::TypeError::IntMismatch)(x),
1013         (ty::error::TypeError::FloatMismatch)(x),
1014         (ty::error::TypeError::Traits)(x),
1015         (ty::error::TypeError::VariadicMismatch)(x),
1016         (ty::error::TypeError::CyclicTy)(t),
1017         (ty::error::TypeError::ProjectionMismatched)(x),
1018         (ty::error::TypeError::ProjectionBoundsLength)(x),
1019         (ty::error::TypeError::Sorts)(x),
1020         (ty::error::TypeError::ExistentialMismatch)(x),
1021     }
1022 }
1023
1024 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::LazyConst<'tcx> {
1025     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1026         let new = match self {
1027             ty::LazyConst::Evaluated(v) => ty::LazyConst::Evaluated(v.fold_with(folder)),
1028             ty::LazyConst::Unevaluated(def_id, substs) => {
1029                 ty::LazyConst::Unevaluated(*def_id, substs.fold_with(folder))
1030             }
1031         };
1032         folder.tcx().intern_lazy_const(new)
1033     }
1034
1035     fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1036         folder.fold_const(*self)
1037     }
1038
1039     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1040         match *self {
1041             ty::LazyConst::Evaluated(c) => c.visit_with(visitor),
1042             ty::LazyConst::Unevaluated(_, substs) => substs.visit_with(visitor),
1043         }
1044     }
1045
1046     fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1047         visitor.visit_const(self)
1048     }
1049 }
1050
1051 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> {
1052     fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1053         let ty = self.ty.fold_with(folder);
1054         let val = self.val.fold_with(folder);
1055         folder.tcx().mk_const(ty::Const {
1056             ty,
1057             val
1058         })
1059     }
1060
1061     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1062         self.ty.visit_with(visitor) || self.val.visit_with(visitor)
1063     }
1064 }