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 and proc-macros to help with the tedium.
5 use crate::mir::interpret;
6 use crate::mir::ProjectionKind;
7 use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
8 use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer};
9 use crate::ty::{self, InferConst, Lift, Ty, TyCtxt};
10 use rustc_data_structures::functor::IdFunctor;
11 use rustc_hir::def::Namespace;
12 use rustc_hir::def_id::CRATE_DEF_INDEX;
13 use rustc_index::vec::{Idx, IndexVec};
16 use std::ops::ControlFlow;
20 impl fmt::Debug for ty::TraitDef {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 with_no_trimmed_paths(|| {
24 FmtPrinter::new(tcx, f, Namespace::TypeNS).print_def_path(self.def_id, &[])
31 impl fmt::Debug for ty::AdtDef {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 with_no_trimmed_paths(|| {
35 FmtPrinter::new(tcx, f, Namespace::TypeNS).print_def_path(self.did, &[])
42 impl fmt::Debug for ty::UpvarId {
43 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44 let name = ty::tls::with(|tcx| tcx.hir().name(self.var_path.hir_id));
45 write!(f, "UpvarId({:?};`{}`;{:?})", self.var_path.hir_id, name, self.closure_expr_id)
49 impl fmt::Debug for ty::UpvarBorrow<'tcx> {
50 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51 write!(f, "UpvarBorrow({:?}, {:?})", self.kind, self.region)
55 impl fmt::Debug for ty::ExistentialTraitRef<'tcx> {
56 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57 with_no_trimmed_paths(|| fmt::Display::fmt(self, f))
61 impl fmt::Debug for ty::adjustment::Adjustment<'tcx> {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63 write!(f, "{:?} -> {}", self.kind, self.target)
67 impl fmt::Debug for ty::BoundRegionKind {
68 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
70 ty::BrAnon(n) => write!(f, "BrAnon({:?})", n),
71 ty::BrNamed(did, name) => {
72 if did.index == CRATE_DEF_INDEX {
73 write!(f, "BrNamed({})", name)
75 write!(f, "BrNamed({:?}, {})", did, name)
78 ty::BrEnv => write!(f, "BrEnv"),
83 impl fmt::Debug for ty::RegionKind {
84 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
86 ty::ReEarlyBound(ref data) => write!(f, "ReEarlyBound({}, {})", data.index, data.name),
88 ty::ReLateBound(binder_id, ref bound_region) => {
89 write!(f, "ReLateBound({:?}, {:?})", binder_id, bound_region)
92 ty::ReFree(ref fr) => fr.fmt(f),
94 ty::ReStatic => write!(f, "ReStatic"),
96 ty::ReVar(ref vid) => vid.fmt(f),
98 ty::RePlaceholder(placeholder) => write!(f, "RePlaceholder({:?})", placeholder),
100 ty::ReEmpty(ui) => write!(f, "ReEmpty({:?})", ui),
102 ty::ReErased => write!(f, "ReErased"),
107 impl fmt::Debug for ty::FreeRegion {
108 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
109 write!(f, "ReFree({:?}, {:?})", self.scope, self.bound_region)
113 impl fmt::Debug for ty::FnSig<'tcx> {
114 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
115 write!(f, "({:?}; c_variadic: {})->{:?}", self.inputs(), self.c_variadic, self.output())
119 impl<'tcx> fmt::Debug for ty::ConstVid<'tcx> {
120 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
121 write!(f, "_#{}c", self.index)
125 impl fmt::Debug for ty::RegionVid {
126 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
127 write!(f, "'_#{}r", self.index())
131 impl fmt::Debug for ty::TraitRef<'tcx> {
132 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
133 with_no_trimmed_paths(|| fmt::Display::fmt(self, f))
137 impl fmt::Debug for Ty<'tcx> {
138 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
139 with_no_trimmed_paths(|| fmt::Display::fmt(self, f))
143 impl fmt::Debug for ty::ParamTy {
144 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
145 write!(f, "{}/#{}", self.name, self.index)
149 impl fmt::Debug for ty::ParamConst {
150 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
151 write!(f, "{}/#{}", self.name, self.index)
155 impl fmt::Debug for ty::TraitPredicate<'tcx> {
156 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
157 if let ty::BoundConstness::ConstIfConst = self.constness {
158 write!(f, "~const ")?;
160 write!(f, "TraitPredicate({:?})", self.trait_ref)
164 impl fmt::Debug for ty::ProjectionPredicate<'tcx> {
165 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
166 write!(f, "ProjectionPredicate({:?}, {:?})", self.projection_ty, self.ty)
170 impl fmt::Debug for ty::Predicate<'tcx> {
171 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
172 write!(f, "{:?}", self.kind())
176 impl fmt::Debug for ty::PredicateKind<'tcx> {
177 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
179 ty::PredicateKind::Trait(ref a) => a.fmt(f),
180 ty::PredicateKind::Subtype(ref pair) => pair.fmt(f),
181 ty::PredicateKind::Coerce(ref pair) => pair.fmt(f),
182 ty::PredicateKind::RegionOutlives(ref pair) => pair.fmt(f),
183 ty::PredicateKind::TypeOutlives(ref pair) => pair.fmt(f),
184 ty::PredicateKind::Projection(ref pair) => pair.fmt(f),
185 ty::PredicateKind::WellFormed(data) => write!(f, "WellFormed({:?})", data),
186 ty::PredicateKind::ObjectSafe(trait_def_id) => {
187 write!(f, "ObjectSafe({:?})", trait_def_id)
189 ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
190 write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind)
192 ty::PredicateKind::ConstEvaluatable(uv) => {
193 write!(f, "ConstEvaluatable({:?}, {:?})", uv.def, uv.substs_)
195 ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
196 ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
197 write!(f, "TypeWellFormedFromEnv({:?})", ty)
203 ///////////////////////////////////////////////////////////////////////////
206 // For things that don't carry any arena-allocated data (and are
207 // copy...), just add them to this list.
209 TrivialTypeFoldableAndLiftImpls! {
213 ::rustc_target::abi::VariantIdx,
217 crate::middle::region::Scope,
219 ::rustc_ast::InlineAsmOptions,
220 ::rustc_ast::InlineAsmTemplatePiece,
222 ::rustc_span::symbol::Symbol,
223 ::rustc_hir::def::Res,
224 ::rustc_hir::def_id::DefId,
225 ::rustc_hir::def_id::LocalDefId,
227 ::rustc_hir::LlvmInlineAsmInner,
228 ::rustc_hir::MatchSource,
229 ::rustc_hir::Mutability,
230 ::rustc_hir::Unsafety,
231 ::rustc_target::asm::InlineAsmRegOrRegClass,
232 ::rustc_target::spec::abi::Abi,
233 crate::mir::coverage::ExpressionOperandId,
234 crate::mir::coverage::CounterValueReference,
235 crate::mir::coverage::InjectedExpressionId,
236 crate::mir::coverage::InjectedExpressionIndex,
237 crate::mir::coverage::MappedExpressionIndex,
239 crate::mir::Promoted,
240 crate::traits::Reveal,
241 crate::ty::adjustment::AutoBorrowMutability,
243 crate::ty::BoundConstness,
244 // Including `BoundRegionKind` is a *bit* dubious, but direct
245 // references to bound region appear in `ty::Error`, and aren't
246 // really meant to be folded. In general, we can only fold a fully
248 crate::ty::BoundRegionKind,
249 crate::ty::AssocItem,
250 crate::ty::Placeholder<crate::ty::BoundRegionKind>,
251 crate::ty::ClosureKind,
252 crate::ty::FreeRegion,
254 crate::ty::IntVarValue,
255 crate::ty::ParamConst,
257 crate::ty::adjustment::PointerCast,
258 crate::ty::RegionVid,
259 crate::ty::UniverseIndex,
264 ///////////////////////////////////////////////////////////////////////////
265 // Lift implementations
267 // FIXME(eddyb) replace all the uses of `Option::map` with `?`.
268 impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>> Lift<'tcx> for (A, B) {
269 type Lifted = (A::Lifted, B::Lifted);
270 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
271 Some((tcx.lift(self.0)?, tcx.lift(self.1)?))
275 impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>, C: Lift<'tcx>> Lift<'tcx> for (A, B, C) {
276 type Lifted = (A::Lifted, B::Lifted, C::Lifted);
277 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
278 Some((tcx.lift(self.0)?, tcx.lift(self.1)?, tcx.lift(self.2)?))
282 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
283 type Lifted = Option<T::Lifted>;
284 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
286 Some(x) => tcx.lift(x).map(Some),
292 impl<'tcx, T: Lift<'tcx>, E: Lift<'tcx>> Lift<'tcx> for Result<T, E> {
293 type Lifted = Result<T::Lifted, E::Lifted>;
294 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
296 Ok(x) => tcx.lift(x).map(Ok),
297 Err(e) => tcx.lift(e).map(Err),
302 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Box<T> {
303 type Lifted = Box<T::Lifted>;
304 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
305 tcx.lift(*self).map(Box::new)
309 impl<'tcx, T: Lift<'tcx> + Clone> Lift<'tcx> for Rc<T> {
310 type Lifted = Rc<T::Lifted>;
311 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
312 tcx.lift(self.as_ref().clone()).map(Rc::new)
316 impl<'tcx, T: Lift<'tcx> + Clone> Lift<'tcx> for Arc<T> {
317 type Lifted = Arc<T::Lifted>;
318 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
319 tcx.lift(self.as_ref().clone()).map(Arc::new)
322 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Vec<T> {
323 type Lifted = Vec<T::Lifted>;
324 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
325 self.into_iter().map(|v| tcx.lift(v)).collect()
329 impl<'tcx, I: Idx, T: Lift<'tcx>> Lift<'tcx> for IndexVec<I, T> {
330 type Lifted = IndexVec<I, T::Lifted>;
331 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
332 self.into_iter().map(|e| tcx.lift(e)).collect()
336 impl<'a, 'tcx> Lift<'tcx> for ty::TraitRef<'a> {
337 type Lifted = ty::TraitRef<'tcx>;
338 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
339 tcx.lift(self.substs).map(|substs| ty::TraitRef { def_id: self.def_id, substs })
343 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialTraitRef<'a> {
344 type Lifted = ty::ExistentialTraitRef<'tcx>;
345 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
346 tcx.lift(self.substs).map(|substs| ty::ExistentialTraitRef { def_id: self.def_id, substs })
350 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialPredicate<'a> {
351 type Lifted = ty::ExistentialPredicate<'tcx>;
352 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
354 ty::ExistentialPredicate::Trait(x) => tcx.lift(x).map(ty::ExistentialPredicate::Trait),
355 ty::ExistentialPredicate::Projection(x) => {
356 tcx.lift(x).map(ty::ExistentialPredicate::Projection)
358 ty::ExistentialPredicate::AutoTrait(def_id) => {
359 Some(ty::ExistentialPredicate::AutoTrait(def_id))
365 impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> {
366 type Lifted = ty::TraitPredicate<'tcx>;
367 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ty::TraitPredicate<'tcx>> {
368 tcx.lift(self.trait_ref)
369 .map(|trait_ref| ty::TraitPredicate { trait_ref, constness: self.constness })
373 impl<'a, 'tcx> Lift<'tcx> for ty::SubtypePredicate<'a> {
374 type Lifted = ty::SubtypePredicate<'tcx>;
375 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ty::SubtypePredicate<'tcx>> {
376 tcx.lift((self.a, self.b)).map(|(a, b)| ty::SubtypePredicate {
377 a_is_expected: self.a_is_expected,
384 impl<'a, 'tcx> Lift<'tcx> for ty::CoercePredicate<'a> {
385 type Lifted = ty::CoercePredicate<'tcx>;
386 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ty::CoercePredicate<'tcx>> {
387 tcx.lift((self.a, self.b)).map(|(a, b)| ty::CoercePredicate { a, b })
391 impl<'tcx, A: Copy + Lift<'tcx>, B: Copy + Lift<'tcx>> Lift<'tcx> for ty::OutlivesPredicate<A, B> {
392 type Lifted = ty::OutlivesPredicate<A::Lifted, B::Lifted>;
393 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
394 tcx.lift((self.0, self.1)).map(|(a, b)| ty::OutlivesPredicate(a, b))
398 impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionTy<'a> {
399 type Lifted = ty::ProjectionTy<'tcx>;
400 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ty::ProjectionTy<'tcx>> {
401 tcx.lift(self.substs)
402 .map(|substs| ty::ProjectionTy { item_def_id: self.item_def_id, substs })
406 impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionPredicate<'a> {
407 type Lifted = ty::ProjectionPredicate<'tcx>;
408 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ty::ProjectionPredicate<'tcx>> {
409 tcx.lift((self.projection_ty, self.ty))
410 .map(|(projection_ty, ty)| ty::ProjectionPredicate { projection_ty, ty })
414 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> {
415 type Lifted = ty::ExistentialProjection<'tcx>;
416 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
417 tcx.lift(self.substs).map(|substs| ty::ExistentialProjection {
419 ty: tcx.lift(self.ty).expect("type must lift when substs do"),
420 item_def_id: self.item_def_id,
425 impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
426 type Lifted = ty::PredicateKind<'tcx>;
427 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
429 ty::PredicateKind::Trait(data) => tcx.lift(data).map(ty::PredicateKind::Trait),
430 ty::PredicateKind::Subtype(data) => tcx.lift(data).map(ty::PredicateKind::Subtype),
431 ty::PredicateKind::Coerce(data) => tcx.lift(data).map(ty::PredicateKind::Coerce),
432 ty::PredicateKind::RegionOutlives(data) => {
433 tcx.lift(data).map(ty::PredicateKind::RegionOutlives)
435 ty::PredicateKind::TypeOutlives(data) => {
436 tcx.lift(data).map(ty::PredicateKind::TypeOutlives)
438 ty::PredicateKind::Projection(data) => {
439 tcx.lift(data).map(ty::PredicateKind::Projection)
441 ty::PredicateKind::WellFormed(ty) => tcx.lift(ty).map(ty::PredicateKind::WellFormed),
442 ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
443 tcx.lift(closure_substs).map(|closure_substs| {
444 ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind)
447 ty::PredicateKind::ObjectSafe(trait_def_id) => {
448 Some(ty::PredicateKind::ObjectSafe(trait_def_id))
450 ty::PredicateKind::ConstEvaluatable(uv) => {
451 tcx.lift(uv).map(|uv| ty::PredicateKind::ConstEvaluatable(uv))
453 ty::PredicateKind::ConstEquate(c1, c2) => {
454 tcx.lift((c1, c2)).map(|(c1, c2)| ty::PredicateKind::ConstEquate(c1, c2))
456 ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
457 tcx.lift(ty).map(ty::PredicateKind::TypeWellFormedFromEnv)
463 impl<'a, 'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<'a, T>
465 <T as Lift<'tcx>>::Lifted: TypeFoldable<'tcx>,
467 type Lifted = ty::Binder<'tcx, T::Lifted>;
468 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
469 let bound_vars = tcx.lift(self.bound_vars());
470 tcx.lift(self.skip_binder())
472 .map(|(value, vars)| ty::Binder::bind_with_vars(value, vars))
476 impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> {
477 type Lifted = ty::ParamEnv<'tcx>;
478 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
479 tcx.lift(self.caller_bounds())
480 .map(|caller_bounds| ty::ParamEnv::new(caller_bounds, self.reveal()))
484 impl<'a, 'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::ParamEnvAnd<'a, T> {
485 type Lifted = ty::ParamEnvAnd<'tcx, T::Lifted>;
486 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
487 tcx.lift(self.param_env).and_then(|param_env| {
488 tcx.lift(self.value).map(|value| ty::ParamEnvAnd { param_env, value })
493 impl<'a, 'tcx> Lift<'tcx> for ty::ClosureSubsts<'a> {
494 type Lifted = ty::ClosureSubsts<'tcx>;
495 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
496 tcx.lift(self.substs).map(|substs| ty::ClosureSubsts { substs })
500 impl<'a, 'tcx> Lift<'tcx> for ty::GeneratorSubsts<'a> {
501 type Lifted = ty::GeneratorSubsts<'tcx>;
502 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
503 tcx.lift(self.substs).map(|substs| ty::GeneratorSubsts { substs })
507 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjustment<'a> {
508 type Lifted = ty::adjustment::Adjustment<'tcx>;
509 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
510 let ty::adjustment::Adjustment { kind, target } = self;
511 tcx.lift(kind).and_then(|kind| {
512 tcx.lift(target).map(|target| ty::adjustment::Adjustment { kind, target })
517 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
518 type Lifted = ty::adjustment::Adjust<'tcx>;
519 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
521 ty::adjustment::Adjust::NeverToAny => Some(ty::adjustment::Adjust::NeverToAny),
522 ty::adjustment::Adjust::Pointer(ptr) => Some(ty::adjustment::Adjust::Pointer(ptr)),
523 ty::adjustment::Adjust::Deref(overloaded) => {
524 tcx.lift(overloaded).map(ty::adjustment::Adjust::Deref)
526 ty::adjustment::Adjust::Borrow(autoref) => {
527 tcx.lift(autoref).map(ty::adjustment::Adjust::Borrow)
533 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::OverloadedDeref<'a> {
534 type Lifted = ty::adjustment::OverloadedDeref<'tcx>;
535 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
536 tcx.lift(self.region).map(|region| ty::adjustment::OverloadedDeref {
544 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
545 type Lifted = ty::adjustment::AutoBorrow<'tcx>;
546 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
548 ty::adjustment::AutoBorrow::Ref(r, m) => {
549 tcx.lift(r).map(|r| ty::adjustment::AutoBorrow::Ref(r, m))
551 ty::adjustment::AutoBorrow::RawPtr(m) => Some(ty::adjustment::AutoBorrow::RawPtr(m)),
556 impl<'a, 'tcx> Lift<'tcx> for ty::GenSig<'a> {
557 type Lifted = ty::GenSig<'tcx>;
558 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
559 tcx.lift((self.resume_ty, self.yield_ty, self.return_ty))
560 .map(|(resume_ty, yield_ty, return_ty)| ty::GenSig { resume_ty, yield_ty, return_ty })
564 impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> {
565 type Lifted = ty::FnSig<'tcx>;
566 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
567 tcx.lift(self.inputs_and_output).map(|x| ty::FnSig {
568 inputs_and_output: x,
569 c_variadic: self.c_variadic,
570 unsafety: self.unsafety,
576 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::error::ExpectedFound<T> {
577 type Lifted = ty::error::ExpectedFound<T::Lifted>;
578 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
579 let ty::error::ExpectedFound { expected, found } = self;
580 tcx.lift(expected).and_then(|expected| {
581 tcx.lift(found).map(|found| ty::error::ExpectedFound { expected, found })
586 impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
587 type Lifted = ty::error::TypeError<'tcx>;
588 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
589 use crate::ty::error::TypeError::*;
592 Mismatch => Mismatch,
593 ConstnessMismatch(x) => ConstnessMismatch(x),
594 UnsafetyMismatch(x) => UnsafetyMismatch(x),
595 AbiMismatch(x) => AbiMismatch(x),
596 Mutability => Mutability,
597 ArgumentMutability(i) => ArgumentMutability(i),
598 TupleSize(x) => TupleSize(x),
599 FixedArraySize(x) => FixedArraySize(x),
600 ArgCount => ArgCount,
601 RegionsDoesNotOutlive(a, b) => {
602 return tcx.lift((a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b));
604 RegionsInsufficientlyPolymorphic(a, b) => {
605 return tcx.lift(b).map(|b| RegionsInsufficientlyPolymorphic(a, b));
607 RegionsOverlyPolymorphic(a, b) => {
608 return tcx.lift(b).map(|b| RegionsOverlyPolymorphic(a, b));
610 RegionsPlaceholderMismatch => RegionsPlaceholderMismatch,
611 IntMismatch(x) => IntMismatch(x),
612 FloatMismatch(x) => FloatMismatch(x),
613 Traits(x) => Traits(x),
614 VariadicMismatch(x) => VariadicMismatch(x),
615 CyclicTy(t) => return tcx.lift(t).map(|t| CyclicTy(t)),
616 CyclicConst(ct) => return tcx.lift(ct).map(|ct| CyclicConst(ct)),
617 ProjectionMismatched(x) => ProjectionMismatched(x),
618 ArgumentSorts(x, i) => return tcx.lift(x).map(|x| ArgumentSorts(x, i)),
619 Sorts(x) => return tcx.lift(x).map(Sorts),
620 ExistentialMismatch(x) => return tcx.lift(x).map(ExistentialMismatch),
621 ConstMismatch(x) => return tcx.lift(x).map(ConstMismatch),
622 IntrinsicCast => IntrinsicCast,
623 TargetFeatureCast(x) => TargetFeatureCast(x),
624 ObjectUnsafeCoercion(x) => return tcx.lift(x).map(ObjectUnsafeCoercion),
629 impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
630 type Lifted = ty::InstanceDef<'tcx>;
631 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
633 ty::InstanceDef::Item(def_id) => Some(ty::InstanceDef::Item(def_id)),
634 ty::InstanceDef::VtableShim(def_id) => Some(ty::InstanceDef::VtableShim(def_id)),
635 ty::InstanceDef::ReifyShim(def_id) => Some(ty::InstanceDef::ReifyShim(def_id)),
636 ty::InstanceDef::Intrinsic(def_id) => Some(ty::InstanceDef::Intrinsic(def_id)),
637 ty::InstanceDef::FnPtrShim(def_id, ty) => {
638 Some(ty::InstanceDef::FnPtrShim(def_id, tcx.lift(ty)?))
640 ty::InstanceDef::Virtual(def_id, n) => Some(ty::InstanceDef::Virtual(def_id, n)),
641 ty::InstanceDef::ClosureOnceShim { call_once, track_caller } => {
642 Some(ty::InstanceDef::ClosureOnceShim { call_once, track_caller })
644 ty::InstanceDef::DropGlue(def_id, ty) => {
645 Some(ty::InstanceDef::DropGlue(def_id, tcx.lift(ty)?))
647 ty::InstanceDef::CloneShim(def_id, ty) => {
648 Some(ty::InstanceDef::CloneShim(def_id, tcx.lift(ty)?))
654 ///////////////////////////////////////////////////////////////////////////
655 // TypeFoldable implementations.
657 // Ideally, each type should invoke `folder.fold_foo(self)` and
658 // nothing else. In some cases, though, we haven't gotten around to
659 // adding methods on the `folder` yet, and thus the folding is
660 // hard-coded here. This is less-flexible, because folders cannot
661 // override the behavior, but there are a lot of random types and one
662 // can easily refactor the folding into the TypeFolder trait as
665 /// AdtDefs are basically the same as a DefId.
666 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::AdtDef {
667 fn super_fold_with<F: TypeFolder<'tcx>>(self, _folder: &mut F) -> Self {
671 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<V::BreakTy> {
672 ControlFlow::CONTINUE
676 impl<'tcx, T: TypeFoldable<'tcx>, U: TypeFoldable<'tcx>> TypeFoldable<'tcx> for (T, U) {
677 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> (T, U) {
678 (self.0.fold_with(folder), self.1.fold_with(folder))
681 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
682 self.0.visit_with(visitor)?;
683 self.1.visit_with(visitor)
687 impl<'tcx, A: TypeFoldable<'tcx>, B: TypeFoldable<'tcx>, C: TypeFoldable<'tcx>> TypeFoldable<'tcx>
690 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> (A, B, C) {
691 (self.0.fold_with(folder), self.1.fold_with(folder), self.2.fold_with(folder))
694 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
695 self.0.visit_with(visitor)?;
696 self.1.visit_with(visitor)?;
697 self.2.visit_with(visitor)
701 EnumTypeFoldableImpl! {
702 impl<'tcx, T> TypeFoldable<'tcx> for Option<T> {
705 } where T: TypeFoldable<'tcx>
708 EnumTypeFoldableImpl! {
709 impl<'tcx, T, E> TypeFoldable<'tcx> for Result<T, E> {
712 } where T: TypeFoldable<'tcx>, E: TypeFoldable<'tcx>,
715 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
716 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
717 // FIXME: Reuse the `Rc` here.
718 Rc::new((*self).clone().fold_with(folder))
721 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
722 (**self).visit_with(visitor)
726 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Arc<T> {
727 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
728 // FIXME: Reuse the `Arc` here.
729 Arc::new((*self).clone().fold_with(folder))
732 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
733 (**self).visit_with(visitor)
737 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> {
738 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
739 self.map_id(|value| value.fold_with(folder))
742 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
743 (**self).visit_with(visitor)
747 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
748 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
749 self.map_id(|t| t.fold_with(folder))
752 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
753 self.iter().try_for_each(|t| t.visit_with(visitor))
757 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> {
758 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
759 self.map_id(|t| t.fold_with(folder))
762 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
763 self.iter().try_for_each(|t| t.visit_with(visitor))
767 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<'tcx, T> {
768 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
769 self.map_bound(|ty| ty.fold_with(folder))
772 fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
773 folder.fold_binder(self)
776 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
777 self.as_ref().skip_binder().visit_with(visitor)
780 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
781 visitor.visit_binder(self)
785 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>> {
786 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
787 ty::util::fold_list(self, folder, |tcx, v| tcx.intern_poly_existential_predicates(v))
790 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
791 self.iter().try_for_each(|p| p.visit_with(visitor))
795 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
796 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
797 ty::util::fold_list(self, folder, |tcx, v| tcx.intern_type_list(v))
800 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
801 self.iter().try_for_each(|t| t.visit_with(visitor))
805 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> {
806 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
807 ty::util::fold_list(self, folder, |tcx, v| tcx.intern_projs(v))
810 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
811 self.iter().try_for_each(|t| t.visit_with(visitor))
815 impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
816 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
817 use crate::ty::InstanceDef::*;
819 substs: self.substs.fold_with(folder),
820 def: match self.def {
821 Item(def) => Item(def.fold_with(folder)),
822 VtableShim(did) => VtableShim(did.fold_with(folder)),
823 ReifyShim(did) => ReifyShim(did.fold_with(folder)),
824 Intrinsic(did) => Intrinsic(did.fold_with(folder)),
825 FnPtrShim(did, ty) => FnPtrShim(did.fold_with(folder), ty.fold_with(folder)),
826 Virtual(did, i) => Virtual(did.fold_with(folder), i),
827 ClosureOnceShim { call_once, track_caller } => {
828 ClosureOnceShim { call_once: call_once.fold_with(folder), track_caller }
830 DropGlue(did, ty) => DropGlue(did.fold_with(folder), ty.fold_with(folder)),
831 CloneShim(did, ty) => CloneShim(did.fold_with(folder), ty.fold_with(folder)),
836 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
837 use crate::ty::InstanceDef::*;
838 self.substs.visit_with(visitor)?;
840 Item(def) => def.visit_with(visitor),
841 VtableShim(did) | ReifyShim(did) | Intrinsic(did) | Virtual(did, _) => {
842 did.visit_with(visitor)
844 FnPtrShim(did, ty) | CloneShim(did, ty) => {
845 did.visit_with(visitor)?;
846 ty.visit_with(visitor)
848 DropGlue(did, ty) => {
849 did.visit_with(visitor)?;
850 ty.visit_with(visitor)
852 ClosureOnceShim { call_once, track_caller: _ } => call_once.visit_with(visitor),
857 impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'tcx> {
858 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
859 Self { instance: self.instance.fold_with(folder), promoted: self.promoted }
862 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
863 self.instance.visit_with(visitor)
867 impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
868 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
869 let kind = match *self.kind() {
870 ty::RawPtr(tm) => ty::RawPtr(tm.fold_with(folder)),
871 ty::Array(typ, sz) => ty::Array(typ.fold_with(folder), sz.fold_with(folder)),
872 ty::Slice(typ) => ty::Slice(typ.fold_with(folder)),
873 ty::Adt(tid, substs) => ty::Adt(tid, substs.fold_with(folder)),
874 ty::Dynamic(trait_ty, region) => {
875 ty::Dynamic(trait_ty.fold_with(folder), region.fold_with(folder))
877 ty::Tuple(ts) => ty::Tuple(ts.fold_with(folder)),
878 ty::FnDef(def_id, substs) => ty::FnDef(def_id, substs.fold_with(folder)),
879 ty::FnPtr(f) => ty::FnPtr(f.fold_with(folder)),
880 ty::Ref(r, ty, mutbl) => ty::Ref(r.fold_with(folder), ty.fold_with(folder), mutbl),
881 ty::Generator(did, substs, movability) => {
882 ty::Generator(did, substs.fold_with(folder), movability)
884 ty::GeneratorWitness(types) => ty::GeneratorWitness(types.fold_with(folder)),
885 ty::Closure(did, substs) => ty::Closure(did, substs.fold_with(folder)),
886 ty::Projection(data) => ty::Projection(data.fold_with(folder)),
887 ty::Opaque(did, substs) => ty::Opaque(did, substs.fold_with(folder)),
899 | ty::Placeholder(..)
901 | ty::Foreign(..) => return self,
904 if *self.kind() == kind { self } else { folder.tcx().mk_ty(kind) }
907 fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
911 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
913 ty::RawPtr(ref tm) => tm.visit_with(visitor),
914 ty::Array(typ, sz) => {
915 typ.visit_with(visitor)?;
916 sz.visit_with(visitor)
918 ty::Slice(typ) => typ.visit_with(visitor),
919 ty::Adt(_, substs) => substs.visit_with(visitor),
920 ty::Dynamic(ref trait_ty, ref reg) => {
921 trait_ty.visit_with(visitor)?;
922 reg.visit_with(visitor)
924 ty::Tuple(ts) => ts.visit_with(visitor),
925 ty::FnDef(_, substs) => substs.visit_with(visitor),
926 ty::FnPtr(ref f) => f.visit_with(visitor),
927 ty::Ref(r, ty, _) => {
928 r.visit_with(visitor)?;
929 ty.visit_with(visitor)
931 ty::Generator(_did, ref substs, _) => substs.visit_with(visitor),
932 ty::GeneratorWitness(ref types) => types.visit_with(visitor),
933 ty::Closure(_did, ref substs) => substs.visit_with(visitor),
934 ty::Projection(ref data) => data.visit_with(visitor),
935 ty::Opaque(_, ref substs) => substs.visit_with(visitor),
946 | ty::Placeholder(..)
949 | ty::Foreign(..) => ControlFlow::CONTINUE,
953 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
954 visitor.visit_ty(self)
958 impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
959 fn super_fold_with<F: TypeFolder<'tcx>>(self, _folder: &mut F) -> Self {
963 fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
964 folder.fold_region(self)
967 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<V::BreakTy> {
968 ControlFlow::CONTINUE
971 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
972 visitor.visit_region(*self)
976 impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
977 fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
978 folder.fold_predicate(self)
981 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
982 let new = self.inner.kind.fold_with(folder);
983 folder.tcx().reuse_or_mk_predicate(self, new)
986 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
987 self.inner.kind.visit_with(visitor)
990 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
991 visitor.visit_predicate(*self)
994 fn has_vars_bound_at_or_above(&self, binder: ty::DebruijnIndex) -> bool {
995 self.inner.outer_exclusive_binder > binder
998 fn has_type_flags(&self, flags: ty::TypeFlags) -> bool {
999 self.inner.flags.intersects(flags)
1003 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
1004 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
1005 ty::util::fold_list(self, folder, |tcx, v| tcx.intern_predicates(v))
1008 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1009 self.iter().try_for_each(|p| p.visit_with(visitor))
1013 impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T> {
1014 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
1015 self.map_id(|x| x.fold_with(folder))
1018 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1019 self.iter().try_for_each(|t| t.visit_with(visitor))
1023 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> {
1024 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
1025 let ty = self.ty.fold_with(folder);
1026 let val = self.val.fold_with(folder);
1027 if ty != self.ty || val != self.val {
1028 folder.tcx().mk_const(ty::Const { ty, val })
1034 fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
1035 folder.fold_const(self)
1038 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1039 self.ty.visit_with(visitor)?;
1040 self.val.visit_with(visitor)
1043 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1044 visitor.visit_const(self)
1048 impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> {
1049 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
1051 ty::ConstKind::Infer(ic) => ty::ConstKind::Infer(ic.fold_with(folder)),
1052 ty::ConstKind::Param(p) => ty::ConstKind::Param(p.fold_with(folder)),
1053 ty::ConstKind::Unevaluated(uv) => ty::ConstKind::Unevaluated(uv.fold_with(folder)),
1054 ty::ConstKind::Value(_)
1055 | ty::ConstKind::Bound(..)
1056 | ty::ConstKind::Placeholder(..)
1057 | ty::ConstKind::Error(_) => self,
1061 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1063 ty::ConstKind::Infer(ic) => ic.visit_with(visitor),
1064 ty::ConstKind::Param(p) => p.visit_with(visitor),
1065 ty::ConstKind::Unevaluated(uv) => uv.visit_with(visitor),
1066 ty::ConstKind::Value(_)
1067 | ty::ConstKind::Bound(..)
1068 | ty::ConstKind::Placeholder(_)
1069 | ty::ConstKind::Error(_) => ControlFlow::CONTINUE,
1074 impl<'tcx> TypeFoldable<'tcx> for InferConst<'tcx> {
1075 fn super_fold_with<F: TypeFolder<'tcx>>(self, _folder: &mut F) -> Self {
1079 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<V::BreakTy> {
1080 ControlFlow::CONTINUE
1084 impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx> {
1085 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
1088 substs_: Some(self.substs(folder.tcx()).fold_with(folder)),
1089 promoted: self.promoted,
1093 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1094 visitor.visit_unevaluated_const(*self)
1097 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1098 if let Some(tcx) = visitor.tcx_for_anon_const_substs() {
1099 self.substs(tcx).visit_with(visitor)
1100 } else if let Some(substs) = self.substs_ {
1101 substs.visit_with(visitor)
1103 debug!("ignoring default substs of `{:?}`", self.def);
1104 ControlFlow::CONTINUE
1109 impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx, ()> {
1110 fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
1113 substs_: Some(self.substs(folder.tcx()).fold_with(folder)),
1114 promoted: self.promoted,
1118 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1119 visitor.visit_unevaluated_const(self.expand())
1122 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1123 if let Some(tcx) = visitor.tcx_for_anon_const_substs() {
1124 self.substs(tcx).visit_with(visitor)
1125 } else if let Some(substs) = self.substs_ {
1126 substs.visit_with(visitor)
1128 debug!("ignoring default substs of `{:?}`", self.def);
1129 ControlFlow::CONTINUE