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