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};
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! {
298 crate::ty::layout::VariantIdx,
301 crate::middle::region::Scope,
302 ::syntax::ast::FloatTy,
303 ::syntax::ast::NodeId,
304 ::syntax_pos::symbol::Symbol,
305 crate::hir::def::Res,
306 crate::hir::def_id::DefId,
307 crate::hir::InlineAsm,
308 crate::hir::MatchSource,
309 crate::hir::Mutability,
310 crate::hir::Unsafety,
311 ::rustc_target::spec::abi::Abi,
313 crate::mir::Promoted,
314 crate::traits::Reveal,
315 crate::ty::adjustment::AutoBorrowMutability,
317 // Including `BoundRegion` is a *bit* dubious, but direct
318 // references to bound region appear in `ty::Error`, and aren't
319 // really meant to be folded. In general, we can only fold a fully
321 crate::ty::BoundRegion,
322 crate::ty::Placeholder<crate::ty::BoundRegion>,
323 crate::ty::ClosureKind,
324 crate::ty::FreeRegion,
326 crate::ty::IntVarValue,
327 crate::ty::ParamConst,
329 crate::ty::adjustment::PointerCast,
330 crate::ty::RegionVid,
331 crate::ty::UniverseIndex,
336 ///////////////////////////////////////////////////////////////////////////
337 // Lift implementations
339 // FIXME(eddyb) replace all the uses of `Option::map` with `?`.
340 impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>> Lift<'tcx> for (A, B) {
341 type Lifted = (A::Lifted, B::Lifted);
342 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
343 tcx.lift(&self.0).and_then(|a| tcx.lift(&self.1).map(|b| (a, b)))
347 impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>, C: Lift<'tcx>> Lift<'tcx> for (A, B, C) {
348 type Lifted = (A::Lifted, B::Lifted, C::Lifted);
349 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
350 tcx.lift(&self.0).and_then(|a| {
351 tcx.lift(&self.1).and_then(|b| tcx.lift(&self.2).map(|c| (a, b, c)))
356 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
357 type Lifted = Option<T::Lifted>;
358 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
360 Some(ref x) => tcx.lift(x).map(Some),
366 impl<'tcx, T: Lift<'tcx>, E: Lift<'tcx>> Lift<'tcx> for Result<T, E> {
367 type Lifted = Result<T::Lifted, E::Lifted>;
368 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
370 Ok(ref x) => tcx.lift(x).map(Ok),
371 Err(ref e) => tcx.lift(e).map(Err)
376 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Box<T> {
377 type Lifted = Box<T::Lifted>;
378 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
379 tcx.lift(&**self).map(Box::new)
383 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for [T] {
384 type Lifted = Vec<T::Lifted>;
385 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
386 // type annotation needed to inform `projection_must_outlive`
387 let mut result : Vec<<T as Lift<'tcx>>::Lifted>
388 = Vec::with_capacity(self.len());
390 if let Some(value) = tcx.lift(x) {
400 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Vec<T> {
401 type Lifted = Vec<T::Lifted>;
402 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
407 impl<'tcx, I: Idx, T: Lift<'tcx>> Lift<'tcx> for IndexVec<I, T> {
408 type Lifted = IndexVec<I, T::Lifted>;
409 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
411 .map(|e| tcx.lift(e))
416 impl<'a, 'tcx> Lift<'tcx> for ty::TraitRef<'a> {
417 type Lifted = ty::TraitRef<'tcx>;
418 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
419 tcx.lift(&self.substs).map(|substs| ty::TraitRef {
426 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialTraitRef<'a> {
427 type Lifted = ty::ExistentialTraitRef<'tcx>;
428 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
429 tcx.lift(&self.substs).map(|substs| ty::ExistentialTraitRef {
436 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialPredicate<'a> {
437 type Lifted = ty::ExistentialPredicate<'tcx>;
438 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
440 ty::ExistentialPredicate::Trait(x) => {
441 tcx.lift(x).map(ty::ExistentialPredicate::Trait)
443 ty::ExistentialPredicate::Projection(x) => {
444 tcx.lift(x).map(ty::ExistentialPredicate::Projection)
446 ty::ExistentialPredicate::AutoTrait(def_id) => {
447 Some(ty::ExistentialPredicate::AutoTrait(*def_id))
453 impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> {
454 type Lifted = ty::TraitPredicate<'tcx>;
455 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
456 -> Option<ty::TraitPredicate<'tcx>> {
457 tcx.lift(&self.trait_ref).map(|trait_ref| ty::TraitPredicate {
463 impl<'a, 'tcx> Lift<'tcx> for ty::SubtypePredicate<'a> {
464 type Lifted = ty::SubtypePredicate<'tcx>;
465 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
466 -> Option<ty::SubtypePredicate<'tcx>> {
467 tcx.lift(&(self.a, self.b)).map(|(a, b)| ty::SubtypePredicate {
468 a_is_expected: self.a_is_expected,
475 impl<'tcx, A: Copy+Lift<'tcx>, B: Copy+Lift<'tcx>> Lift<'tcx> for ty::OutlivesPredicate<A, B> {
476 type Lifted = ty::OutlivesPredicate<A::Lifted, B::Lifted>;
477 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
478 tcx.lift(&(self.0, self.1)).map(|(a, b)| ty::OutlivesPredicate(a, b))
482 impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionTy<'a> {
483 type Lifted = ty::ProjectionTy<'tcx>;
484 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
485 -> Option<ty::ProjectionTy<'tcx>> {
486 tcx.lift(&self.substs).map(|substs| {
488 item_def_id: self.item_def_id,
495 impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionPredicate<'a> {
496 type Lifted = ty::ProjectionPredicate<'tcx>;
497 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>)
498 -> Option<ty::ProjectionPredicate<'tcx>> {
499 tcx.lift(&(self.projection_ty, self.ty)).map(|(projection_ty, ty)| {
500 ty::ProjectionPredicate {
508 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> {
509 type Lifted = ty::ExistentialProjection<'tcx>;
510 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
511 tcx.lift(&self.substs).map(|substs| {
512 ty::ExistentialProjection {
514 ty: tcx.lift(&self.ty).expect("type must lift when substs do"),
515 item_def_id: self.item_def_id,
521 impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> {
522 type Lifted = ty::Predicate<'tcx>;
523 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
525 ty::Predicate::Trait(ref binder) => {
526 tcx.lift(binder).map(ty::Predicate::Trait)
528 ty::Predicate::Subtype(ref binder) => {
529 tcx.lift(binder).map(ty::Predicate::Subtype)
531 ty::Predicate::RegionOutlives(ref binder) => {
532 tcx.lift(binder).map(ty::Predicate::RegionOutlives)
534 ty::Predicate::TypeOutlives(ref binder) => {
535 tcx.lift(binder).map(ty::Predicate::TypeOutlives)
537 ty::Predicate::Projection(ref binder) => {
538 tcx.lift(binder).map(ty::Predicate::Projection)
540 ty::Predicate::WellFormed(ty) => {
541 tcx.lift(&ty).map(ty::Predicate::WellFormed)
543 ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
544 tcx.lift(&closure_substs)
545 .map(|closure_substs| ty::Predicate::ClosureKind(closure_def_id,
549 ty::Predicate::ObjectSafe(trait_def_id) => {
550 Some(ty::Predicate::ObjectSafe(trait_def_id))
552 ty::Predicate::ConstEvaluatable(def_id, substs) => {
553 tcx.lift(&substs).map(|substs| {
554 ty::Predicate::ConstEvaluatable(def_id, substs)
561 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<T> {
562 type Lifted = ty::Binder<T::Lifted>;
563 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
564 tcx.lift(self.skip_binder()).map(ty::Binder::bind)
568 impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> {
569 type Lifted = ty::ParamEnv<'tcx>;
570 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
571 tcx.lift(&self.caller_bounds).map(|caller_bounds| {
581 impl<'a, 'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::ParamEnvAnd<'a, T> {
582 type Lifted = ty::ParamEnvAnd<'tcx, T::Lifted>;
583 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
584 tcx.lift(&self.param_env).and_then(|param_env| {
585 tcx.lift(&self.value).map(|value| {
595 impl<'a, 'tcx> Lift<'tcx> for ty::ClosureSubsts<'a> {
596 type Lifted = ty::ClosureSubsts<'tcx>;
597 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
598 tcx.lift(&self.substs).map(|substs| {
599 ty::ClosureSubsts { substs }
604 impl<'a, 'tcx> Lift<'tcx> for ty::GeneratorSubsts<'a> {
605 type Lifted = ty::GeneratorSubsts<'tcx>;
606 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
607 tcx.lift(&self.substs).map(|substs| {
608 ty::GeneratorSubsts { substs }
613 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjustment<'a> {
614 type Lifted = ty::adjustment::Adjustment<'tcx>;
615 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
616 tcx.lift(&self.kind).and_then(|kind| {
617 tcx.lift(&self.target).map(|target| {
618 ty::adjustment::Adjustment { kind, target }
624 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
625 type Lifted = ty::adjustment::Adjust<'tcx>;
626 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
628 ty::adjustment::Adjust::NeverToAny =>
629 Some(ty::adjustment::Adjust::NeverToAny),
630 ty::adjustment::Adjust::Pointer(ptr) =>
631 Some(ty::adjustment::Adjust::Pointer(ptr)),
632 ty::adjustment::Adjust::Deref(ref overloaded) => {
633 tcx.lift(overloaded).map(ty::adjustment::Adjust::Deref)
635 ty::adjustment::Adjust::Borrow(ref autoref) => {
636 tcx.lift(autoref).map(ty::adjustment::Adjust::Borrow)
642 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::OverloadedDeref<'a> {
643 type Lifted = ty::adjustment::OverloadedDeref<'tcx>;
644 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
645 tcx.lift(&self.region).map(|region| {
646 ty::adjustment::OverloadedDeref {
654 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
655 type Lifted = ty::adjustment::AutoBorrow<'tcx>;
656 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
658 ty::adjustment::AutoBorrow::Ref(r, m) => {
659 tcx.lift(&r).map(|r| ty::adjustment::AutoBorrow::Ref(r, m))
661 ty::adjustment::AutoBorrow::RawPtr(m) => {
662 Some(ty::adjustment::AutoBorrow::RawPtr(m))
668 impl<'a, 'tcx> Lift<'tcx> for ty::GenSig<'a> {
669 type Lifted = ty::GenSig<'tcx>;
670 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
671 tcx.lift(&(self.yield_ty, self.return_ty))
672 .map(|(yield_ty, return_ty)| {
681 impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> {
682 type Lifted = ty::FnSig<'tcx>;
683 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
684 tcx.lift(&self.inputs_and_output).map(|x| {
686 inputs_and_output: x,
687 c_variadic: self.c_variadic,
688 unsafety: self.unsafety,
695 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::error::ExpectedFound<T> {
696 type Lifted = ty::error::ExpectedFound<T::Lifted>;
697 fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> {
698 tcx.lift(&self.expected).and_then(|expected| {
699 tcx.lift(&self.found).map(|found| {
700 ty::error::ExpectedFound {
709 impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
710 type Lifted = ty::error::TypeError<'tcx>;
711 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
712 use crate::ty::error::TypeError::*;
715 Mismatch => Mismatch,
716 UnsafetyMismatch(x) => UnsafetyMismatch(x),
717 AbiMismatch(x) => AbiMismatch(x),
718 Mutability => Mutability,
719 TupleSize(x) => TupleSize(x),
720 FixedArraySize(x) => FixedArraySize(x),
721 ArgCount => ArgCount,
722 RegionsDoesNotOutlive(a, b) => {
723 return tcx.lift(&(a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b))
725 RegionsInsufficientlyPolymorphic(a, b) => {
726 return tcx.lift(&b).map(|b| RegionsInsufficientlyPolymorphic(a, b))
728 RegionsOverlyPolymorphic(a, b) => {
729 return tcx.lift(&b).map(|b| RegionsOverlyPolymorphic(a, b))
731 RegionsPlaceholderMismatch => RegionsPlaceholderMismatch,
732 IntMismatch(x) => IntMismatch(x),
733 FloatMismatch(x) => FloatMismatch(x),
734 Traits(x) => Traits(x),
735 VariadicMismatch(x) => VariadicMismatch(x),
736 CyclicTy(t) => return tcx.lift(&t).map(|t| CyclicTy(t)),
737 ProjectionMismatched(x) => ProjectionMismatched(x),
738 ProjectionBoundsLength(x) => ProjectionBoundsLength(x),
739 Sorts(ref x) => return tcx.lift(x).map(Sorts),
740 ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch),
741 ConstMismatch(ref x) => return tcx.lift(x).map(ConstMismatch),
746 impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
747 type Lifted = ty::InstanceDef<'tcx>;
748 fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
750 ty::InstanceDef::Item(def_id) =>
751 Some(ty::InstanceDef::Item(def_id)),
752 ty::InstanceDef::VtableShim(def_id) =>
753 Some(ty::InstanceDef::VtableShim(def_id)),
754 ty::InstanceDef::Intrinsic(def_id) =>
755 Some(ty::InstanceDef::Intrinsic(def_id)),
756 ty::InstanceDef::FnPtrShim(def_id, ref ty) =>
757 Some(ty::InstanceDef::FnPtrShim(def_id, tcx.lift(ty)?)),
758 ty::InstanceDef::Virtual(def_id, n) =>
759 Some(ty::InstanceDef::Virtual(def_id, n)),
760 ty::InstanceDef::ClosureOnceShim { call_once } =>
761 Some(ty::InstanceDef::ClosureOnceShim { call_once }),
762 ty::InstanceDef::DropGlue(def_id, ref ty) =>
763 Some(ty::InstanceDef::DropGlue(def_id, tcx.lift(ty)?)),
764 ty::InstanceDef::CloneShim(def_id, ref ty) =>
765 Some(ty::InstanceDef::CloneShim(def_id, tcx.lift(ty)?)),
770 BraceStructLiftImpl! {
771 impl<'a, 'tcx> Lift<'tcx> for ty::TypeAndMut<'a> {
772 type Lifted = ty::TypeAndMut<'tcx>;
777 BraceStructLiftImpl! {
778 impl<'a, 'tcx> Lift<'tcx> for ty::Instance<'a> {
779 type Lifted = ty::Instance<'tcx>;
784 BraceStructLiftImpl! {
785 impl<'a, 'tcx> Lift<'tcx> for interpret::GlobalId<'a> {
786 type Lifted = interpret::GlobalId<'tcx>;
791 impl<'a, 'tcx> Lift<'tcx> for ConstVid<'a> {
792 type Lifted = ConstVid<'tcx>;
793 fn lift_to_tcx<'b, 'gcx>(&self, _: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
796 phantom: PhantomData,
801 ///////////////////////////////////////////////////////////////////////////
802 // TypeFoldable implementations.
804 // Ideally, each type should invoke `folder.fold_foo(self)` and
805 // nothing else. In some cases, though, we haven't gotten around to
806 // adding methods on the `folder` yet, and thus the folding is
807 // hard-coded here. This is less-flexible, because folders cannot
808 // override the behavior, but there are a lot of random types and one
809 // can easily refactor the folding into the TypeFolder trait as
812 /// AdtDefs are basically the same as a DefId.
813 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::AdtDef {
814 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _folder: &mut F) -> Self {
818 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
823 impl<'tcx, T:TypeFoldable<'tcx>, U:TypeFoldable<'tcx>> TypeFoldable<'tcx> for (T, U) {
824 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> (T, U) {
825 (self.0.fold_with(folder), self.1.fold_with(folder))
828 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
829 self.0.visit_with(visitor) || self.1.visit_with(visitor)
833 EnumTypeFoldableImpl! {
834 impl<'tcx, T> TypeFoldable<'tcx> for Option<T> {
837 } where T: TypeFoldable<'tcx>
840 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
841 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
842 Rc::new((**self).fold_with(folder))
845 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
846 (**self).visit_with(visitor)
850 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> {
851 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
852 let content: T = (**self).fold_with(folder);
856 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
857 (**self).visit_with(visitor)
861 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
862 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
863 self.iter().map(|t| t.fold_with(folder)).collect()
866 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
867 self.iter().any(|t| t.visit_with(visitor))
871 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> {
872 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
873 self.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>().into_boxed_slice()
876 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
877 self.iter().any(|t| t.visit_with(visitor))
881 impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
882 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
883 self.map_bound_ref(|ty| ty.fold_with(folder))
886 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
887 folder.fold_binder(self)
890 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
891 self.skip_binder().visit_with(visitor)
894 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
895 visitor.visit_binder(self)
899 BraceStructTypeFoldableImpl! {
900 impl<'tcx> TypeFoldable<'tcx> for ty::ParamEnv<'tcx> { reveal, caller_bounds, def_id }
903 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {
904 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
905 let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
906 folder.tcx().intern_existential_predicates(&v)
909 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
910 self.iter().any(|p| p.visit_with(visitor))
914 EnumTypeFoldableImpl! {
915 impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialPredicate<'tcx> {
916 (ty::ExistentialPredicate::Trait)(a),
917 (ty::ExistentialPredicate::Projection)(a),
918 (ty::ExistentialPredicate::AutoTrait)(a),
922 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
923 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
924 let v = self.iter().map(|t| t.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
925 folder.tcx().intern_type_list(&v)
928 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
929 self.iter().any(|t| t.visit_with(visitor))
933 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> {
934 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
935 let v = self.iter().map(|t| t.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
936 folder.tcx().intern_projs(&v)
939 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
940 self.iter().any(|t| t.visit_with(visitor))
944 impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
945 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
946 use crate::ty::InstanceDef::*;
948 substs: self.substs.fold_with(folder),
949 def: match self.def {
950 Item(did) => Item(did.fold_with(folder)),
951 VtableShim(did) => VtableShim(did.fold_with(folder)),
952 Intrinsic(did) => Intrinsic(did.fold_with(folder)),
953 FnPtrShim(did, ty) => FnPtrShim(
954 did.fold_with(folder),
955 ty.fold_with(folder),
957 Virtual(did, i) => Virtual(
958 did.fold_with(folder),
961 ClosureOnceShim { call_once } => ClosureOnceShim {
962 call_once: call_once.fold_with(folder),
964 DropGlue(did, ty) => DropGlue(
965 did.fold_with(folder),
966 ty.fold_with(folder),
968 CloneShim(did, ty) => CloneShim(
969 did.fold_with(folder),
970 ty.fold_with(folder),
976 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
977 use crate::ty::InstanceDef::*;
978 self.substs.visit_with(visitor) ||
980 Item(did) | VtableShim(did) | Intrinsic(did) | Virtual(did, _) => {
981 did.visit_with(visitor)
983 FnPtrShim(did, ty) | CloneShim(did, ty) => {
984 did.visit_with(visitor) || ty.visit_with(visitor)
986 DropGlue(did, ty) => {
987 did.visit_with(visitor) || ty.visit_with(visitor)
989 ClosureOnceShim { call_once } => call_once.visit_with(visitor),
994 impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'tcx> {
995 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
997 instance: self.instance.fold_with(folder),
998 promoted: self.promoted
1002 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1003 self.instance.visit_with(visitor)
1007 impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
1008 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1009 let sty = match self.sty {
1010 ty::RawPtr(tm) => ty::RawPtr(tm.fold_with(folder)),
1011 ty::Array(typ, sz) => ty::Array(typ.fold_with(folder), sz.fold_with(folder)),
1012 ty::Slice(typ) => ty::Slice(typ.fold_with(folder)),
1013 ty::Adt(tid, substs) => ty::Adt(tid, substs.fold_with(folder)),
1014 ty::Dynamic(ref trait_ty, ref region) =>
1015 ty::Dynamic(trait_ty.fold_with(folder), region.fold_with(folder)),
1016 ty::Tuple(ts) => ty::Tuple(ts.fold_with(folder)),
1017 ty::FnDef(def_id, substs) => {
1018 ty::FnDef(def_id, substs.fold_with(folder))
1020 ty::FnPtr(f) => ty::FnPtr(f.fold_with(folder)),
1021 ty::Ref(ref r, ty, mutbl) => {
1022 ty::Ref(r.fold_with(folder), ty.fold_with(folder), mutbl)
1024 ty::Generator(did, substs, movability) => {
1027 substs.fold_with(folder),
1030 ty::GeneratorWitness(types) => ty::GeneratorWitness(types.fold_with(folder)),
1031 ty::Closure(did, substs) => ty::Closure(did, substs.fold_with(folder)),
1032 ty::Projection(ref data) => ty::Projection(data.fold_with(folder)),
1033 ty::UnnormalizedProjection(ref data) => {
1034 ty::UnnormalizedProjection(data.fold_with(folder))
1036 ty::Opaque(did, substs) => ty::Opaque(did, substs.fold_with(folder)),
1048 ty::Placeholder(..) |
1050 ty::Foreign(..) => return self
1053 if self.sty == sty {
1056 folder.tcx().mk_ty(sty)
1060 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1061 folder.fold_ty(*self)
1064 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1066 ty::RawPtr(ref tm) => tm.visit_with(visitor),
1067 ty::Array(typ, sz) => typ.visit_with(visitor) || sz.visit_with(visitor),
1068 ty::Slice(typ) => typ.visit_with(visitor),
1069 ty::Adt(_, substs) => substs.visit_with(visitor),
1070 ty::Dynamic(ref trait_ty, ref reg) =>
1071 trait_ty.visit_with(visitor) || reg.visit_with(visitor),
1072 ty::Tuple(ts) => ts.visit_with(visitor),
1073 ty::FnDef(_, substs) => substs.visit_with(visitor),
1074 ty::FnPtr(ref f) => f.visit_with(visitor),
1075 ty::Ref(r, ty, _) => r.visit_with(visitor) || ty.visit_with(visitor),
1076 ty::Generator(_did, ref substs, _) => {
1077 substs.visit_with(visitor)
1079 ty::GeneratorWitness(ref types) => types.visit_with(visitor),
1080 ty::Closure(_did, ref substs) => substs.visit_with(visitor),
1081 ty::Projection(ref data) | ty::UnnormalizedProjection(ref data) => {
1082 data.visit_with(visitor)
1084 ty::Opaque(_, ref substs) => substs.visit_with(visitor),
1095 ty::Placeholder(..) |
1098 ty::Foreign(..) => false,
1102 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1103 visitor.visit_ty(self)
1107 BraceStructTypeFoldableImpl! {
1108 impl<'tcx> TypeFoldable<'tcx> for ty::TypeAndMut<'tcx> {
1113 BraceStructTypeFoldableImpl! {
1114 impl<'tcx> TypeFoldable<'tcx> for ty::GenSig<'tcx> {
1119 BraceStructTypeFoldableImpl! {
1120 impl<'tcx> TypeFoldable<'tcx> for ty::FnSig<'tcx> {
1121 inputs_and_output, c_variadic, unsafety, abi
1125 BraceStructTypeFoldableImpl! {
1126 impl<'tcx> TypeFoldable<'tcx> for ty::TraitRef<'tcx> { def_id, substs }
1129 BraceStructTypeFoldableImpl! {
1130 impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialTraitRef<'tcx> { def_id, substs }
1133 BraceStructTypeFoldableImpl! {
1134 impl<'tcx> TypeFoldable<'tcx> for ty::ImplHeader<'tcx> {
1142 impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
1143 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _folder: &mut F) -> Self {
1147 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1148 folder.fold_region(*self)
1151 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool {
1155 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1156 visitor.visit_region(*self)
1160 BraceStructTypeFoldableImpl! {
1161 impl<'tcx> TypeFoldable<'tcx> for ty::ClosureSubsts<'tcx> {
1166 BraceStructTypeFoldableImpl! {
1167 impl<'tcx> TypeFoldable<'tcx> for ty::GeneratorSubsts<'tcx> {
1172 BraceStructTypeFoldableImpl! {
1173 impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::Adjustment<'tcx> {
1179 EnumTypeFoldableImpl! {
1180 impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::Adjust<'tcx> {
1181 (ty::adjustment::Adjust::NeverToAny),
1182 (ty::adjustment::Adjust::Pointer)(a),
1183 (ty::adjustment::Adjust::Deref)(a),
1184 (ty::adjustment::Adjust::Borrow)(a),
1188 BraceStructTypeFoldableImpl! {
1189 impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::OverloadedDeref<'tcx> {
1194 EnumTypeFoldableImpl! {
1195 impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::AutoBorrow<'tcx> {
1196 (ty::adjustment::AutoBorrow::Ref)(a, b),
1197 (ty::adjustment::AutoBorrow::RawPtr)(m),
1201 BraceStructTypeFoldableImpl! {
1202 impl<'tcx> TypeFoldable<'tcx> for ty::GenericPredicates<'tcx> {
1207 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
1208 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1209 let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
1210 folder.tcx().intern_predicates(&v)
1213 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1214 self.iter().any(|p| p.visit_with(visitor))
1218 EnumTypeFoldableImpl! {
1219 impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
1220 (ty::Predicate::Trait)(a),
1221 (ty::Predicate::Subtype)(a),
1222 (ty::Predicate::RegionOutlives)(a),
1223 (ty::Predicate::TypeOutlives)(a),
1224 (ty::Predicate::Projection)(a),
1225 (ty::Predicate::WellFormed)(a),
1226 (ty::Predicate::ClosureKind)(a, b, c),
1227 (ty::Predicate::ObjectSafe)(a),
1228 (ty::Predicate::ConstEvaluatable)(a, b),
1232 BraceStructTypeFoldableImpl! {
1233 impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionPredicate<'tcx> {
1238 BraceStructTypeFoldableImpl! {
1239 impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialProjection<'tcx> {
1240 ty, substs, item_def_id
1244 BraceStructTypeFoldableImpl! {
1245 impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionTy<'tcx> {
1250 BraceStructTypeFoldableImpl! {
1251 impl<'tcx> TypeFoldable<'tcx> for ty::InstantiatedPredicates<'tcx> {
1256 BraceStructTypeFoldableImpl! {
1257 impl<'tcx, T> TypeFoldable<'tcx> for ty::ParamEnvAnd<'tcx, T> {
1259 } where T: TypeFoldable<'tcx>
1262 BraceStructTypeFoldableImpl! {
1263 impl<'tcx> TypeFoldable<'tcx> for ty::SubtypePredicate<'tcx> {
1268 BraceStructTypeFoldableImpl! {
1269 impl<'tcx> TypeFoldable<'tcx> for ty::TraitPredicate<'tcx> {
1274 TupleStructTypeFoldableImpl! {
1275 impl<'tcx,T,U> TypeFoldable<'tcx> for ty::OutlivesPredicate<T,U> {
1277 } where T : TypeFoldable<'tcx>, U : TypeFoldable<'tcx>,
1280 BraceStructTypeFoldableImpl! {
1281 impl<'tcx> TypeFoldable<'tcx> for ty::ClosureUpvar<'tcx> {
1286 BraceStructTypeFoldableImpl! {
1287 impl<'tcx, T> TypeFoldable<'tcx> for ty::error::ExpectedFound<T> {
1289 } where T: TypeFoldable<'tcx>
1292 impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T> {
1293 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1294 self.iter().map(|x| x.fold_with(folder)).collect()
1297 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1298 self.iter().any(|t| t.visit_with(visitor))
1302 EnumTypeFoldableImpl! {
1303 impl<'tcx> TypeFoldable<'tcx> for ty::error::TypeError<'tcx> {
1304 (ty::error::TypeError::Mismatch),
1305 (ty::error::TypeError::UnsafetyMismatch)(x),
1306 (ty::error::TypeError::AbiMismatch)(x),
1307 (ty::error::TypeError::Mutability),
1308 (ty::error::TypeError::TupleSize)(x),
1309 (ty::error::TypeError::FixedArraySize)(x),
1310 (ty::error::TypeError::ArgCount),
1311 (ty::error::TypeError::RegionsDoesNotOutlive)(a, b),
1312 (ty::error::TypeError::RegionsInsufficientlyPolymorphic)(a, b),
1313 (ty::error::TypeError::RegionsOverlyPolymorphic)(a, b),
1314 (ty::error::TypeError::RegionsPlaceholderMismatch),
1315 (ty::error::TypeError::IntMismatch)(x),
1316 (ty::error::TypeError::FloatMismatch)(x),
1317 (ty::error::TypeError::Traits)(x),
1318 (ty::error::TypeError::VariadicMismatch)(x),
1319 (ty::error::TypeError::CyclicTy)(t),
1320 (ty::error::TypeError::ProjectionMismatched)(x),
1321 (ty::error::TypeError::ProjectionBoundsLength)(x),
1322 (ty::error::TypeError::Sorts)(x),
1323 (ty::error::TypeError::ExistentialMismatch)(x),
1324 (ty::error::TypeError::ConstMismatch)(x),
1328 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> {
1329 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1330 let ty = self.ty.fold_with(folder);
1331 let val = self.val.fold_with(folder);
1332 folder.tcx().mk_const(ty::Const {
1338 fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1339 folder.fold_const(*self)
1342 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1343 self.ty.visit_with(visitor) || self.val.visit_with(visitor)
1346 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1347 visitor.visit_const(self)
1351 impl<'tcx> TypeFoldable<'tcx> for ConstValue<'tcx> {
1352 fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
1354 ConstValue::ByRef(ptr, alloc) => ConstValue::ByRef(ptr, alloc),
1355 // FIXME(const_generics): implement TypeFoldable for InferConst
1356 ConstValue::Infer(ic) => ConstValue::Infer(ic),
1357 ConstValue::Param(p) => ConstValue::Param(p.fold_with(folder)),
1358 ConstValue::Placeholder(p) => ConstValue::Placeholder(p),
1359 ConstValue::Scalar(a) => ConstValue::Scalar(a),
1360 ConstValue::Slice(a, b) => ConstValue::Slice(a, b),
1361 ConstValue::Unevaluated(did, substs)
1362 => ConstValue::Unevaluated(did, substs.fold_with(folder)),
1366 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1368 ConstValue::ByRef(..) => false,
1369 // FIXME(const_generics): implement TypeFoldable for InferConst
1370 ConstValue::Infer(_) => false,
1371 ConstValue::Param(p) => p.visit_with(visitor),
1372 ConstValue::Placeholder(_) => false,
1373 ConstValue::Scalar(_) => false,
1374 ConstValue::Slice(..) => false,
1375 ConstValue::Unevaluated(_, substs) => substs.visit_with(visitor),