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.
6 use crate::hir::def::Namespace;
7 use crate::mir::ProjectionKind;
8 use crate::mir::interpret::ConstValue;
9 use crate::ty::{self, Lift, Ty, TyCtxt, ConstVid, InferConst};
10 use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
11 use crate::ty::print::{FmtPrinter, Printer};
12 use rustc_data_structures::indexed_vec::{IndexVec, Idx};
13 use smallvec::SmallVec;
14 use crate::mir::interpret;
17 use std::marker::PhantomData;
20 impl fmt::Debug for ty::GenericParamDef {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 let type_name = match self.kind {
23 ty::GenericParamDefKind::Lifetime => "Lifetime",
24 ty::GenericParamDefKind::Type {..} => "Type",
25 ty::GenericParamDefKind::Const => "Const",
27 write!(f, "{}({}, {:?}, {})",
35 impl fmt::Debug for ty::TraitDef {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 FmtPrinter::new(tcx, f, Namespace::TypeNS)
39 .print_def_path(self.def_id, &[])?;
45 impl fmt::Debug for ty::AdtDef {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 FmtPrinter::new(tcx, f, Namespace::TypeNS)
49 .print_def_path(self.did, &[])?;
55 impl fmt::Debug for ty::ClosureUpvar<'tcx> {
56 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57 write!(f, "ClosureUpvar({:?},{:?})",
63 impl fmt::Debug for ty::UpvarId {
64 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65 let name = ty::tls::with(|tcx| {
66 tcx.hir().name_by_hir_id(self.var_path.hir_id)
68 write!(f, "UpvarId({:?};`{}`;{:?})",
75 impl fmt::Debug for ty::UpvarBorrow<'tcx> {
76 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
77 write!(f, "UpvarBorrow({:?}, {:?})",
78 self.kind, self.region)
82 impl fmt::Debug for ty::ExistentialTraitRef<'tcx> {
83 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
84 fmt::Display::fmt(self, f)
88 impl fmt::Debug for ty::adjustment::Adjustment<'tcx> {
89 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
90 write!(f, "{:?} -> {}", self.kind, self.target)
94 impl fmt::Debug for ty::BoundRegion {
95 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
97 ty::BrAnon(n) => write!(f, "BrAnon({:?})", n),
98 ty::BrFresh(n) => write!(f, "BrFresh({:?})", n),
99 ty::BrNamed(did, name) => {
100 write!(f, "BrNamed({:?}:{:?}, {})",
101 did.krate, did.index, name)
103 ty::BrEnv => write!(f, "BrEnv"),
108 impl fmt::Debug for ty::RegionKind {
109 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
111 ty::ReEarlyBound(ref data) => {
112 write!(f, "ReEarlyBound({}, {})",
117 ty::ReClosureBound(ref vid) => {
118 write!(f, "ReClosureBound({:?})", vid)
121 ty::ReLateBound(binder_id, ref bound_region) => {
122 write!(f, "ReLateBound({:?}, {:?})", binder_id, bound_region)
125 ty::ReFree(ref fr) => fr.fmt(f),
127 ty::ReScope(id) => write!(f, "ReScope({:?})", id),
129 ty::ReStatic => write!(f, "ReStatic"),
131 ty::ReVar(ref vid) => vid.fmt(f),
133 ty::RePlaceholder(placeholder) => {
134 write!(f, "RePlaceholder({:?})", placeholder)
137 ty::ReEmpty => write!(f, "ReEmpty"),
139 ty::ReErased => write!(f, "ReErased"),
144 impl fmt::Debug for ty::FreeRegion {
145 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
146 write!(f, "ReFree({:?}, {:?})", self.scope, self.bound_region)
150 impl fmt::Debug for ty::Variance {
151 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
152 f.write_str(match *self {
153 ty::Covariant => "+",
154 ty::Contravariant => "-",
155 ty::Invariant => "o",
156 ty::Bivariant => "*",
161 impl fmt::Debug for ty::FnSig<'tcx> {
162 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
163 write!(f, "({:?}; c_variadic: {})->{:?}",
164 self.inputs(), self.c_variadic, self.output())
168 impl fmt::Debug for ty::TyVid {
169 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
170 write!(f, "_#{}t", self.index)
174 impl<'tcx> fmt::Debug for ty::ConstVid<'tcx> {
175 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
176 write!(f, "_#{}c", self.index)
180 impl fmt::Debug for ty::IntVid {
181 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
182 write!(f, "_#{}i", self.index)
186 impl fmt::Debug for ty::FloatVid {
187 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
188 write!(f, "_#{}f", self.index)
192 impl fmt::Debug for ty::RegionVid {
193 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
194 write!(f, "'_#{}r", self.index())
198 impl fmt::Debug for ty::InferTy {
199 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
201 ty::TyVar(ref v) => v.fmt(f),
202 ty::IntVar(ref v) => v.fmt(f),
203 ty::FloatVar(ref v) => v.fmt(f),
204 ty::FreshTy(v) => write!(f, "FreshTy({:?})", v),
205 ty::FreshIntTy(v) => write!(f, "FreshIntTy({:?})", v),
206 ty::FreshFloatTy(v) => write!(f, "FreshFloatTy({:?})", v),
211 impl fmt::Debug for ty::IntVarValue {
212 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
214 ty::IntType(ref v) => v.fmt(f),
215 ty::UintType(ref v) => v.fmt(f),
220 impl fmt::Debug for ty::FloatVarValue {
221 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
226 impl fmt::Debug for ty::TraitRef<'tcx> {
227 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
228 // FIXME(#59188) this is used across the compiler to print
229 // a `TraitRef` qualified (with the Self type explicit),
230 // instead of having a different way to make that choice.
231 write!(f, "<{} as {}>", self.self_ty(), self)
235 impl fmt::Debug for Ty<'tcx> {
236 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
237 fmt::Display::fmt(self, f)
241 impl fmt::Debug for ty::ParamTy {
242 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
243 write!(f, "{}/#{}", self.name, self.index)
247 impl fmt::Debug for ty::ParamConst {
248 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
249 write!(f, "{}/#{}", self.name, self.index)
253 impl fmt::Debug for ty::TraitPredicate<'tcx> {
254 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
255 write!(f, "TraitPredicate({:?})", self.trait_ref)
259 impl fmt::Debug for ty::ProjectionPredicate<'tcx> {
260 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
261 write!(f, "ProjectionPredicate({:?}, {:?})", self.projection_ty, self.ty)
265 impl fmt::Debug for ty::Predicate<'tcx> {
266 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
268 ty::Predicate::Trait(ref a) => a.fmt(f),
269 ty::Predicate::Subtype(ref pair) => pair.fmt(f),
270 ty::Predicate::RegionOutlives(ref pair) => pair.fmt(f),
271 ty::Predicate::TypeOutlives(ref pair) => pair.fmt(f),
272 ty::Predicate::Projection(ref pair) => pair.fmt(f),
273 ty::Predicate::WellFormed(ty) => write!(f, "WellFormed({:?})", ty),
274 ty::Predicate::ObjectSafe(trait_def_id) => {
275 write!(f, "ObjectSafe({:?})", trait_def_id)
277 ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
278 write!(f, "ClosureKind({:?}, {:?}, {:?})",
279 closure_def_id, closure_substs, kind)
281 ty::Predicate::ConstEvaluatable(def_id, substs) => {
282 write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs)
288 ///////////////////////////////////////////////////////////////////////////
291 // For things that don't carry any arena-allocated data (and are
292 // copy...), just add them to this list.
294 CloneTypeFoldableAndLiftImpls! {
300 crate::ty::DebruijnIndex,
301 crate::ty::layout::VariantIdx,
304 crate::middle::region::Scope,
305 ::syntax::ast::FloatTy,
306 ::syntax::ast::NodeId,
307 ::syntax_pos::symbol::Symbol,
308 crate::hir::def::Res,
309 crate::hir::def_id::DefId,
310 crate::hir::InlineAsm,
311 crate::hir::MatchSource,
312 crate::hir::Mutability,
313 crate::hir::Unsafety,
314 ::rustc_target::spec::abi::Abi,
316 crate::mir::Promoted,
317 crate::mir::interpret::Scalar,
318 crate::mir::interpret::Pointer,
319 crate::traits::Reveal,
320 crate::ty::adjustment::AutoBorrowMutability,
322 // Including `BoundRegion` is a *bit* dubious, but direct
323 // references to bound region appear in `ty::Error`, and aren't
324 // really meant to be folded. In general, we can only fold a fully
326 crate::ty::BoundRegion,
327 crate::ty::Placeholder<crate::ty::BoundRegion>,
328 crate::ty::ClosureKind,
329 crate::ty::FreeRegion,
331 crate::ty::IntVarValue,
332 crate::ty::ParamConst,
334 crate::ty::adjustment::PointerCast,
335 crate::ty::RegionVid,
336 crate::ty::UniverseIndex,
341 ///////////////////////////////////////////////////////////////////////////
342 // Lift implementations
344 // FIXME(eddyb) replace all the uses of `Option::map` with `?`.
345 impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>> Lift<'tcx> for (A, B) {
346 type Lifted = (A::Lifted, B::Lifted);
347 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
348 tcx.lift(&self.0).and_then(|a| tcx.lift(&self.1).map(|b| (a, b)))
352 impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>, C: Lift<'tcx>> Lift<'tcx> for (A, B, C) {
353 type Lifted = (A::Lifted, B::Lifted, C::Lifted);
354 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
355 tcx.lift(&self.0).and_then(|a| {
356 tcx.lift(&self.1).and_then(|b| tcx.lift(&self.2).map(|c| (a, b, c)))
361 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
362 type Lifted = Option<T::Lifted>;
363 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
365 Some(ref x) => tcx.lift(x).map(Some),
371 impl<'tcx, T: Lift<'tcx>, E: Lift<'tcx>> Lift<'tcx> for Result<T, E> {
372 type Lifted = Result<T::Lifted, E::Lifted>;
373 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
375 Ok(ref x) => tcx.lift(x).map(Ok),
376 Err(ref e) => tcx.lift(e).map(Err)
381 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Box<T> {
382 type Lifted = Box<T::Lifted>;
383 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
384 tcx.lift(&**self).map(Box::new)
388 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for [T] {
389 type Lifted = Vec<T::Lifted>;
390 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
391 // type annotation needed to inform `projection_must_outlive`
392 let mut result : Vec<<T as Lift<'tcx>>::Lifted>
393 = Vec::with_capacity(self.len());
395 if let Some(value) = tcx.lift(x) {
405 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Vec<T> {
406 type Lifted = Vec<T::Lifted>;
407 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
412 impl<'tcx, I: Idx, T: Lift<'tcx>> Lift<'tcx> for IndexVec<I, T> {
413 type Lifted = IndexVec<I, T::Lifted>;
414 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
416 .map(|e| tcx.lift(e))
421 impl<'a, 'tcx> Lift<'tcx> for ty::TraitRef<'a> {
422 type Lifted = ty::TraitRef<'tcx>;
423 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
424 tcx.lift(&self.substs).map(|substs| ty::TraitRef {
431 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialTraitRef<'a> {
432 type Lifted = ty::ExistentialTraitRef<'tcx>;
433 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
434 tcx.lift(&self.substs).map(|substs| ty::ExistentialTraitRef {
441 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialPredicate<'a> {
442 type Lifted = ty::ExistentialPredicate<'tcx>;
443 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
445 ty::ExistentialPredicate::Trait(x) => {
446 tcx.lift(x).map(ty::ExistentialPredicate::Trait)
448 ty::ExistentialPredicate::Projection(x) => {
449 tcx.lift(x).map(ty::ExistentialPredicate::Projection)
451 ty::ExistentialPredicate::AutoTrait(def_id) => {
452 Some(ty::ExistentialPredicate::AutoTrait(*def_id))
458 impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> {
459 type Lifted = ty::TraitPredicate<'tcx>;
460 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
461 -> Option<ty::TraitPredicate<'tcx>> {
462 tcx.lift(&self.trait_ref).map(|trait_ref| ty::TraitPredicate {
468 impl<'a, 'tcx> Lift<'tcx> for ty::SubtypePredicate<'a> {
469 type Lifted = ty::SubtypePredicate<'tcx>;
470 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
471 -> Option<ty::SubtypePredicate<'tcx>> {
472 tcx.lift(&(self.a, self.b)).map(|(a, b)| ty::SubtypePredicate {
473 a_is_expected: self.a_is_expected,
480 impl<'tcx, A: Copy+Lift<'tcx>, B: Copy+Lift<'tcx>> Lift<'tcx> for ty::OutlivesPredicate<A, B> {
481 type Lifted = ty::OutlivesPredicate<A::Lifted, B::Lifted>;
482 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
483 tcx.lift(&(self.0, self.1)).map(|(a, b)| ty::OutlivesPredicate(a, b))
487 impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionTy<'a> {
488 type Lifted = ty::ProjectionTy<'tcx>;
489 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
490 -> Option<ty::ProjectionTy<'tcx>> {
491 tcx.lift(&self.substs).map(|substs| {
493 item_def_id: self.item_def_id,
500 impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionPredicate<'a> {
501 type Lifted = ty::ProjectionPredicate<'tcx>;
502 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
503 -> Option<ty::ProjectionPredicate<'tcx>> {
504 tcx.lift(&(self.projection_ty, self.ty)).map(|(projection_ty, ty)| {
505 ty::ProjectionPredicate {
513 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> {
514 type Lifted = ty::ExistentialProjection<'tcx>;
515 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
516 tcx.lift(&self.substs).map(|substs| {
517 ty::ExistentialProjection {
519 ty: tcx.lift(&self.ty).expect("type must lift when substs do"),
520 item_def_id: self.item_def_id,
526 impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> {
527 type Lifted = ty::Predicate<'tcx>;
528 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
530 ty::Predicate::Trait(ref binder) => {
531 tcx.lift(binder).map(ty::Predicate::Trait)
533 ty::Predicate::Subtype(ref binder) => {
534 tcx.lift(binder).map(ty::Predicate::Subtype)
536 ty::Predicate::RegionOutlives(ref binder) => {
537 tcx.lift(binder).map(ty::Predicate::RegionOutlives)
539 ty::Predicate::TypeOutlives(ref binder) => {
540 tcx.lift(binder).map(ty::Predicate::TypeOutlives)
542 ty::Predicate::Projection(ref binder) => {
543 tcx.lift(binder).map(ty::Predicate::Projection)
545 ty::Predicate::WellFormed(ty) => {
546 tcx.lift(&ty).map(ty::Predicate::WellFormed)
548 ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
549 tcx.lift(&closure_substs)
550 .map(|closure_substs| ty::Predicate::ClosureKind(closure_def_id,
554 ty::Predicate::ObjectSafe(trait_def_id) => {
555 Some(ty::Predicate::ObjectSafe(trait_def_id))
557 ty::Predicate::ConstEvaluatable(def_id, substs) => {
558 tcx.lift(&substs).map(|substs| {
559 ty::Predicate::ConstEvaluatable(def_id, substs)
566 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<T> {
567 type Lifted = ty::Binder<T::Lifted>;
568 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
569 tcx.lift(self.skip_binder()).map(ty::Binder::bind)
573 impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> {
574 type Lifted = ty::ParamEnv<'tcx>;
575 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
576 tcx.lift(&self.caller_bounds).map(|caller_bounds| {
586 impl<'a, 'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::ParamEnvAnd<'a, T> {
587 type Lifted = ty::ParamEnvAnd<'tcx, T::Lifted>;
588 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
589 tcx.lift(&self.param_env).and_then(|param_env| {
590 tcx.lift(&self.value).map(|value| {
600 impl<'a, 'tcx> Lift<'tcx> for ty::ClosureSubsts<'a> {
601 type Lifted = ty::ClosureSubsts<'tcx>;
602 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
603 tcx.lift(&self.substs).map(|substs| {
604 ty::ClosureSubsts { substs }
609 impl<'a, 'tcx> Lift<'tcx> for ty::GeneratorSubsts<'a> {
610 type Lifted = ty::GeneratorSubsts<'tcx>;
611 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
612 tcx.lift(&self.substs).map(|substs| {
613 ty::GeneratorSubsts { substs }
618 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjustment<'a> {
619 type Lifted = ty::adjustment::Adjustment<'tcx>;
620 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
621 tcx.lift(&self.kind).and_then(|kind| {
622 tcx.lift(&self.target).map(|target| {
623 ty::adjustment::Adjustment { kind, target }
629 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
630 type Lifted = ty::adjustment::Adjust<'tcx>;
631 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
633 ty::adjustment::Adjust::NeverToAny =>
634 Some(ty::adjustment::Adjust::NeverToAny),
635 ty::adjustment::Adjust::Pointer(ptr) =>
636 Some(ty::adjustment::Adjust::Pointer(ptr)),
637 ty::adjustment::Adjust::Deref(ref overloaded) => {
638 tcx.lift(overloaded).map(ty::adjustment::Adjust::Deref)
640 ty::adjustment::Adjust::Borrow(ref autoref) => {
641 tcx.lift(autoref).map(ty::adjustment::Adjust::Borrow)
647 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::OverloadedDeref<'a> {
648 type Lifted = ty::adjustment::OverloadedDeref<'tcx>;
649 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
650 tcx.lift(&self.region).map(|region| {
651 ty::adjustment::OverloadedDeref {
659 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
660 type Lifted = ty::adjustment::AutoBorrow<'tcx>;
661 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
663 ty::adjustment::AutoBorrow::Ref(r, m) => {
664 tcx.lift(&r).map(|r| ty::adjustment::AutoBorrow::Ref(r, m))
666 ty::adjustment::AutoBorrow::RawPtr(m) => {
667 Some(ty::adjustment::AutoBorrow::RawPtr(m))
673 impl<'a, 'tcx> Lift<'tcx> for ty::GenSig<'a> {
674 type Lifted = ty::GenSig<'tcx>;
675 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
676 tcx.lift(&(self.yield_ty, self.return_ty))
677 .map(|(yield_ty, return_ty)| {
686 impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> {
687 type Lifted = ty::FnSig<'tcx>;
688 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
689 tcx.lift(&self.inputs_and_output).map(|x| {
691 inputs_and_output: x,
692 c_variadic: self.c_variadic,
693 unsafety: self.unsafety,
700 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::error::ExpectedFound<T> {
701 type Lifted = ty::error::ExpectedFound<T::Lifted>;
702 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
703 tcx.lift(&self.expected).and_then(|expected| {
704 tcx.lift(&self.found).map(|found| {
705 ty::error::ExpectedFound {
714 impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
715 type Lifted = ty::error::TypeError<'tcx>;
716 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
717 use crate::ty::error::TypeError::*;
720 Mismatch => Mismatch,
721 UnsafetyMismatch(x) => UnsafetyMismatch(x),
722 AbiMismatch(x) => AbiMismatch(x),
723 Mutability => Mutability,
724 TupleSize(x) => TupleSize(x),
725 FixedArraySize(x) => FixedArraySize(x),
726 ArgCount => ArgCount,
727 RegionsDoesNotOutlive(a, b) => {
728 return tcx.lift(&(a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b))
730 RegionsInsufficientlyPolymorphic(a, b) => {
731 return tcx.lift(&b).map(|b| RegionsInsufficientlyPolymorphic(a, b))
733 RegionsOverlyPolymorphic(a, b) => {
734 return tcx.lift(&b).map(|b| RegionsOverlyPolymorphic(a, b))
736 RegionsPlaceholderMismatch => RegionsPlaceholderMismatch,
737 IntMismatch(x) => IntMismatch(x),
738 FloatMismatch(x) => FloatMismatch(x),
739 Traits(x) => Traits(x),
740 VariadicMismatch(x) => VariadicMismatch(x),
741 CyclicTy(t) => return tcx.lift(&t).map(|t| CyclicTy(t)),
742 ProjectionMismatched(x) => ProjectionMismatched(x),
743 ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
744 Sorts(ref x) => return tcx.lift(x).map(Sorts),
745 ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch),
746 ConstMismatch(ref x) => return tcx.lift(x).map(ConstMismatch),
751 impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
752 type Lifted = ty::InstanceDef<'tcx>;
753 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
755 ty::InstanceDef::Item(def_id) =>
756 Some(ty::InstanceDef::Item(def_id)),
757 ty::InstanceDef::VtableShim(def_id) =>
758 Some(ty::InstanceDef::VtableShim(def_id)),
759 ty::InstanceDef::Intrinsic(def_id) =>
760 Some(ty::InstanceDef::Intrinsic(def_id)),
761 ty::InstanceDef::FnPtrShim(def_id, ref ty) =>
762 Some(ty::InstanceDef::FnPtrShim(def_id, tcx.lift(ty)?)),
763 ty::InstanceDef::Virtual(def_id, n) =>
764 Some(ty::InstanceDef::Virtual(def_id, n)),
765 ty::InstanceDef::ClosureOnceShim { call_once } =>
766 Some(ty::InstanceDef::ClosureOnceShim { call_once }),
767 ty::InstanceDef::DropGlue(def_id, ref ty) =>
768 Some(ty::InstanceDef::DropGlue(def_id, tcx.lift(ty)?)),
769 ty::InstanceDef::CloneShim(def_id, ref ty) =>
770 Some(ty::InstanceDef::CloneShim(def_id, tcx.lift(ty)?)),
775 BraceStructLiftImpl! {
776 impl<'a, 'tcx> Lift<'tcx> for ty::TypeAndMut<'a> {
777 type Lifted = ty::TypeAndMut<'tcx>;
782 BraceStructLiftImpl! {
783 impl<'a, 'tcx> Lift<'tcx> for ty::Instance<'a> {
784 type Lifted = ty::Instance<'tcx>;
789 BraceStructLiftImpl! {
790 impl<'a, 'tcx> Lift<'tcx> for interpret::GlobalId<'a> {
791 type Lifted = interpret::GlobalId<'tcx>;
796 BraceStructLiftImpl! {
797 impl<'a, 'tcx> Lift<'tcx> for ty::Const<'a> {
798 type Lifted = ty::Const<'tcx>;
804 impl<'a, 'tcx> Lift<'tcx> for interpret::ConstValue<'a> {
805 type Lifted = interpret::ConstValue<'tcx>;
806 (interpret::ConstValue::Unevaluated)(a, b),
807 (interpret::ConstValue::Param)(a),
808 (interpret::ConstValue::Infer)(a),
809 (interpret::ConstValue::Scalar)(a),
810 (interpret::ConstValue::Slice)(a, b),
811 (interpret::ConstValue::ByRef)(a, b),
816 impl<'a, 'tcx> Lift<'tcx> for ty::InferConst<'a> {
817 type Lifted = ty::InferConst<'tcx>;
818 (ty::InferConst::Var)(a),
819 (ty::InferConst::Fresh)(a),
820 (ty::InferConst::Canonical)(a, b),
824 impl<'a, 'tcx> Lift<'tcx> for ConstVid<'a> {
825 type Lifted = ConstVid<'tcx>;
826 fn lift_to_tcx<'b, 'gcx>(&self, _: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
829 phantom: PhantomData,
834 ///////////////////////////////////////////////////////////////////////////
835 // TypeFoldable implementations.
837 // Ideally, each type should invoke `folder.fold_foo(self)` and
838 // nothing else. In some cases, though, we haven't gotten around to
839 // adding methods on the `folder` yet, and thus the folding is
840 // hard-coded here. This is less-flexible, because folders cannot
841 // override the behavior, but there are a lot of random types and one
842 // can easily refactor the folding into the TypeFolder trait as
845 /// AdtDefs are basically the same as a DefId.
846 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::AdtDef {
847 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _folder: &mut F) -> Self {
851 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
856 impl<'tcx, T:TypeFoldable<'tcx>, U:TypeFoldable<'tcx>> TypeFoldable<'tcx> for (T, U) {
857 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> (T, U) {
858 (self.0.fold_with(folder), self.1.fold_with(folder))
861 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
862 self.0.visit_with(visitor) || self.1.visit_with(visitor)
866 EnumTypeFoldableImpl! {
867 impl<'tcx, T> TypeFoldable<'tcx> for Option<T> {
870 } where T: TypeFoldable<'tcx>
873 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
874 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
875 Rc::new((**self).fold_with(folder))
878 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
879 (**self).visit_with(visitor)
883 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> {
884 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
885 let content: T = (**self).fold_with(folder);
889 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
890 (**self).visit_with(visitor)
894 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
895 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
896 self.iter().map(|t| t.fold_with(folder)).collect()
899 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
900 self.iter().any(|t| t.visit_with(visitor))
904 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> {
905 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
906 self.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>().into_boxed_slice()
909 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
910 self.iter().any(|t| t.visit_with(visitor))
914 impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
915 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
916 self.map_bound_ref(|ty| ty.fold_with(folder))
919 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
920 folder.fold_binder(self)
923 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
924 self.skip_binder().visit_with(visitor)
927 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
928 visitor.visit_binder(self)
932 BraceStructTypeFoldableImpl! {
933 impl<'tcx> TypeFoldable<'tcx> for ty::ParamEnv<'tcx> { reveal, caller_bounds, def_id }
936 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {
937 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
938 let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
939 folder.tcx().intern_existential_predicates(&v)
942 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
943 self.iter().any(|p| p.visit_with(visitor))
947 EnumTypeFoldableImpl! {
948 impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialPredicate<'tcx> {
949 (ty::ExistentialPredicate::Trait)(a),
950 (ty::ExistentialPredicate::Projection)(a),
951 (ty::ExistentialPredicate::AutoTrait)(a),
955 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
956 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
957 let v = self.iter().map(|t| t.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
958 folder.tcx().intern_type_list(&v)
961 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
962 self.iter().any(|t| t.visit_with(visitor))
966 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> {
967 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
968 let v = self.iter().map(|t| t.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
969 folder.tcx().intern_projs(&v)
972 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
973 self.iter().any(|t| t.visit_with(visitor))
977 impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
978 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
979 use crate::ty::InstanceDef::*;
981 substs: self.substs.fold_with(folder),
982 def: match self.def {
983 Item(did) => Item(did.fold_with(folder)),
984 VtableShim(did) => VtableShim(did.fold_with(folder)),
985 Intrinsic(did) => Intrinsic(did.fold_with(folder)),
986 FnPtrShim(did, ty) => FnPtrShim(
987 did.fold_with(folder),
988 ty.fold_with(folder),
990 Virtual(did, i) => Virtual(
991 did.fold_with(folder),
994 ClosureOnceShim { call_once } => ClosureOnceShim {
995 call_once: call_once.fold_with(folder),
997 DropGlue(did, ty) => DropGlue(
998 did.fold_with(folder),
999 ty.fold_with(folder),
1001 CloneShim(did, ty) => CloneShim(
1002 did.fold_with(folder),
1003 ty.fold_with(folder),
1009 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1010 use crate::ty::InstanceDef::*;
1011 self.substs.visit_with(visitor) ||
1013 Item(did) | VtableShim(did) | Intrinsic(did) | Virtual(did, _) => {
1014 did.visit_with(visitor)
1016 FnPtrShim(did, ty) | CloneShim(did, ty) => {
1017 did.visit_with(visitor) || ty.visit_with(visitor)
1019 DropGlue(did, ty) => {
1020 did.visit_with(visitor) || ty.visit_with(visitor)
1022 ClosureOnceShim { call_once } => call_once.visit_with(visitor),
1027 impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'tcx> {
1028 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1030 instance: self.instance.fold_with(folder),
1031 promoted: self.promoted
1035 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1036 self.instance.visit_with(visitor)
1040 impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
1041 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1042 let sty = match self.sty {
1043 ty::RawPtr(tm) => ty::RawPtr(tm.fold_with(folder)),
1044 ty::Array(typ, sz) => ty::Array(typ.fold_with(folder), sz.fold_with(folder)),
1045 ty::Slice(typ) => ty::Slice(typ.fold_with(folder)),
1046 ty::Adt(tid, substs) => ty::Adt(tid, substs.fold_with(folder)),
1047 ty::Dynamic(ref trait_ty, ref region) =>
1048 ty::Dynamic(trait_ty.fold_with(folder), region.fold_with(folder)),
1049 ty::Tuple(ts) => ty::Tuple(ts.fold_with(folder)),
1050 ty::FnDef(def_id, substs) => {
1051 ty::FnDef(def_id, substs.fold_with(folder))
1053 ty::FnPtr(f) => ty::FnPtr(f.fold_with(folder)),
1054 ty::Ref(ref r, ty, mutbl) => {
1055 ty::Ref(r.fold_with(folder), ty.fold_with(folder), mutbl)
1057 ty::Generator(did, substs, movability) => {
1060 substs.fold_with(folder),
1063 ty::GeneratorWitness(types) => ty::GeneratorWitness(types.fold_with(folder)),
1064 ty::Closure(did, substs) => ty::Closure(did, substs.fold_with(folder)),
1065 ty::Projection(ref data) => ty::Projection(data.fold_with(folder)),
1066 ty::UnnormalizedProjection(ref data) => {
1067 ty::UnnormalizedProjection(data.fold_with(folder))
1069 ty::Opaque(did, substs) => ty::Opaque(did, substs.fold_with(folder)),
1081 ty::Placeholder(..) |
1083 ty::Foreign(..) => return self
1086 if self.sty == sty {
1089 folder.tcx().mk_ty(sty)
1093 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1094 folder.fold_ty(*self)
1097 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1099 ty::RawPtr(ref tm) => tm.visit_with(visitor),
1100 ty::Array(typ, sz) => typ.visit_with(visitor) || sz.visit_with(visitor),
1101 ty::Slice(typ) => typ.visit_with(visitor),
1102 ty::Adt(_, substs) => substs.visit_with(visitor),
1103 ty::Dynamic(ref trait_ty, ref reg) =>
1104 trait_ty.visit_with(visitor) || reg.visit_with(visitor),
1105 ty::Tuple(ts) => ts.visit_with(visitor),
1106 ty::FnDef(_, substs) => substs.visit_with(visitor),
1107 ty::FnPtr(ref f) => f.visit_with(visitor),
1108 ty::Ref(r, ty, _) => r.visit_with(visitor) || ty.visit_with(visitor),
1109 ty::Generator(_did, ref substs, _) => {
1110 substs.visit_with(visitor)
1112 ty::GeneratorWitness(ref types) => types.visit_with(visitor),
1113 ty::Closure(_did, ref substs) => substs.visit_with(visitor),
1114 ty::Projection(ref data) | ty::UnnormalizedProjection(ref data) => {
1115 data.visit_with(visitor)
1117 ty::Opaque(_, ref substs) => substs.visit_with(visitor),
1128 ty::Placeholder(..) |
1131 ty::Foreign(..) => false,
1135 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1136 visitor.visit_ty(self)
1140 BraceStructTypeFoldableImpl! {
1141 impl<'tcx> TypeFoldable<'tcx> for ty::TypeAndMut<'tcx> {
1146 BraceStructTypeFoldableImpl! {
1147 impl<'tcx> TypeFoldable<'tcx> for ty::GenSig<'tcx> {
1152 BraceStructTypeFoldableImpl! {
1153 impl<'tcx> TypeFoldable<'tcx> for ty::FnSig<'tcx> {
1154 inputs_and_output, c_variadic, unsafety, abi
1158 BraceStructTypeFoldableImpl! {
1159 impl<'tcx> TypeFoldable<'tcx> for ty::TraitRef<'tcx> { def_id, substs }
1162 BraceStructTypeFoldableImpl! {
1163 impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialTraitRef<'tcx> { def_id, substs }
1166 BraceStructTypeFoldableImpl! {
1167 impl<'tcx> TypeFoldable<'tcx> for ty::ImplHeader<'tcx> {
1175 impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
1176 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _folder: &mut F) -> Self {
1180 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1181 folder.fold_region(*self)
1184 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
1188 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1189 visitor.visit_region(*self)
1193 BraceStructTypeFoldableImpl! {
1194 impl<'tcx> TypeFoldable<'tcx> for ty::ClosureSubsts<'tcx> {
1199 BraceStructTypeFoldableImpl! {
1200 impl<'tcx> TypeFoldable<'tcx> for ty::GeneratorSubsts<'tcx> {
1205 BraceStructTypeFoldableImpl! {
1206 impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::Adjustment<'tcx> {
1212 EnumTypeFoldableImpl! {
1213 impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::Adjust<'tcx> {
1214 (ty::adjustment::Adjust::NeverToAny),
1215 (ty::adjustment::Adjust::Pointer)(a),
1216 (ty::adjustment::Adjust::Deref)(a),
1217 (ty::adjustment::Adjust::Borrow)(a),
1221 BraceStructTypeFoldableImpl! {
1222 impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::OverloadedDeref<'tcx> {
1227 EnumTypeFoldableImpl! {
1228 impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::AutoBorrow<'tcx> {
1229 (ty::adjustment::AutoBorrow::Ref)(a, b),
1230 (ty::adjustment::AutoBorrow::RawPtr)(m),
1234 BraceStructTypeFoldableImpl! {
1235 impl<'tcx> TypeFoldable<'tcx> for ty::GenericPredicates<'tcx> {
1240 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
1241 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1242 let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
1243 folder.tcx().intern_predicates(&v)
1246 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1247 self.iter().any(|p| p.visit_with(visitor))
1251 EnumTypeFoldableImpl! {
1252 impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
1253 (ty::Predicate::Trait)(a),
1254 (ty::Predicate::Subtype)(a),
1255 (ty::Predicate::RegionOutlives)(a),
1256 (ty::Predicate::TypeOutlives)(a),
1257 (ty::Predicate::Projection)(a),
1258 (ty::Predicate::WellFormed)(a),
1259 (ty::Predicate::ClosureKind)(a, b, c),
1260 (ty::Predicate::ObjectSafe)(a),
1261 (ty::Predicate::ConstEvaluatable)(a, b),
1265 BraceStructTypeFoldableImpl! {
1266 impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionPredicate<'tcx> {
1271 BraceStructTypeFoldableImpl! {
1272 impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialProjection<'tcx> {
1273 ty, substs, item_def_id
1277 BraceStructTypeFoldableImpl! {
1278 impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionTy<'tcx> {
1283 BraceStructTypeFoldableImpl! {
1284 impl<'tcx> TypeFoldable<'tcx> for ty::InstantiatedPredicates<'tcx> {
1289 BraceStructTypeFoldableImpl! {
1290 impl<'tcx, T> TypeFoldable<'tcx> for ty::ParamEnvAnd<'tcx, T> {
1292 } where T: TypeFoldable<'tcx>
1295 BraceStructTypeFoldableImpl! {
1296 impl<'tcx> TypeFoldable<'tcx> for ty::SubtypePredicate<'tcx> {
1301 BraceStructTypeFoldableImpl! {
1302 impl<'tcx> TypeFoldable<'tcx> for ty::TraitPredicate<'tcx> {
1307 TupleStructTypeFoldableImpl! {
1308 impl<'tcx,T,U> TypeFoldable<'tcx> for ty::OutlivesPredicate<T,U> {
1310 } where T : TypeFoldable<'tcx>, U : TypeFoldable<'tcx>,
1313 BraceStructTypeFoldableImpl! {
1314 impl<'tcx> TypeFoldable<'tcx> for ty::ClosureUpvar<'tcx> {
1319 BraceStructTypeFoldableImpl! {
1320 impl<'tcx, T> TypeFoldable<'tcx> for ty::error::ExpectedFound<T> {
1322 } where T: TypeFoldable<'tcx>
1325 impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T> {
1326 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1327 self.iter().map(|x| x.fold_with(folder)).collect()
1330 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1331 self.iter().any(|t| t.visit_with(visitor))
1335 EnumTypeFoldableImpl! {
1336 impl<'tcx> TypeFoldable<'tcx> for ty::error::TypeError<'tcx> {
1337 (ty::error::TypeError::Mismatch),
1338 (ty::error::TypeError::UnsafetyMismatch)(x),
1339 (ty::error::TypeError::AbiMismatch)(x),
1340 (ty::error::TypeError::Mutability),
1341 (ty::error::TypeError::TupleSize)(x),
1342 (ty::error::TypeError::FixedArraySize)(x),
1343 (ty::error::TypeError::ArgCount),
1344 (ty::error::TypeError::RegionsDoesNotOutlive)(a, b),
1345 (ty::error::TypeError::RegionsInsufficientlyPolymorphic)(a, b),
1346 (ty::error::TypeError::RegionsOverlyPolymorphic)(a, b),
1347 (ty::error::TypeError::RegionsPlaceholderMismatch),
1348 (ty::error::TypeError::IntMismatch)(x),
1349 (ty::error::TypeError::FloatMismatch)(x),
1350 (ty::error::TypeError::Traits)(x),
1351 (ty::error::TypeError::VariadicMismatch)(x),
1352 (ty::error::TypeError::CyclicTy)(t),
1353 (ty::error::TypeError::ProjectionMismatched)(x),
1354 (ty::error::TypeError::ProjectionBoundsLength)(x),
1355 (ty::error::TypeError::Sorts)(x),
1356 (ty::error::TypeError::ExistentialMismatch)(x),
1357 (ty::error::TypeError::ConstMismatch)(x),
1361 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> {
1362 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1363 let ty = self.ty.fold_with(folder);
1364 let val = self.val.fold_with(folder);
1365 folder.tcx().mk_const(ty::Const {
1371 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1372 folder.fold_const(*self)
1375 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1376 self.ty.visit_with(visitor) || self.val.visit_with(visitor)
1379 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1380 visitor.visit_const(self)
1384 impl<'tcx> TypeFoldable<'tcx> for ConstValue<'tcx> {
1385 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1387 ConstValue::ByRef(ptr, alloc) => ConstValue::ByRef(ptr, alloc),
1388 ConstValue::Infer(ic) => ConstValue::Infer(ic.fold_with(folder)),
1389 ConstValue::Param(p) => ConstValue::Param(p.fold_with(folder)),
1390 ConstValue::Placeholder(p) => ConstValue::Placeholder(p),
1391 ConstValue::Scalar(a) => ConstValue::Scalar(a),
1392 ConstValue::Slice(a, b) => ConstValue::Slice(a, b),
1393 ConstValue::Unevaluated(did, substs)
1394 => ConstValue::Unevaluated(did, substs.fold_with(folder)),
1398 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1400 ConstValue::ByRef(..) => false,
1401 ConstValue::Infer(ic) => ic.visit_with(visitor),
1402 ConstValue::Param(p) => p.visit_with(visitor),
1403 ConstValue::Placeholder(_) => false,
1404 ConstValue::Scalar(_) => false,
1405 ConstValue::Slice(..) => false,
1406 ConstValue::Unevaluated(_, substs) => substs.visit_with(visitor),
1411 impl<'tcx> TypeFoldable<'tcx> for InferConst<'tcx> {
1412 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _folder: &mut F) -> Self {
1416 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {