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::{FallibleTypeFolder, TypeFoldable, TypeVisitor};
8 use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer};
9 use crate::ty::{self, InferConst, Lift, Term, 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::mem::ManuallyDrop;
17 use std::ops::ControlFlow;
21 impl fmt::Debug for ty::TraitDef {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 with_no_trimmed_paths(|| {
25 FmtPrinter::new(tcx, f, Namespace::TypeNS).print_def_path(self.def_id, &[])
32 impl fmt::Debug for ty::AdtDef {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35 with_no_trimmed_paths(|| {
36 FmtPrinter::new(tcx, f, Namespace::TypeNS).print_def_path(self.did, &[])
43 impl fmt::Debug for ty::UpvarId {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 let name = ty::tls::with(|tcx| tcx.hir().name(self.var_path.hir_id));
46 write!(f, "UpvarId({:?};`{}`;{:?})", self.var_path.hir_id, name, self.closure_expr_id)
50 impl<'tcx> fmt::Debug for ty::ExistentialTraitRef<'tcx> {
51 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52 with_no_trimmed_paths(|| fmt::Display::fmt(self, f))
56 impl<'tcx> fmt::Debug for ty::adjustment::Adjustment<'tcx> {
57 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58 write!(f, "{:?} -> {}", self.kind, self.target)
62 impl fmt::Debug for ty::BoundRegionKind {
63 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65 ty::BrAnon(n) => write!(f, "BrAnon({:?})", n),
66 ty::BrNamed(did, name) => {
67 if did.index == CRATE_DEF_INDEX {
68 write!(f, "BrNamed({})", name)
70 write!(f, "BrNamed({:?}, {})", did, name)
73 ty::BrEnv => write!(f, "BrEnv"),
78 impl fmt::Debug for ty::RegionKind {
79 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81 ty::ReEarlyBound(ref data) => write!(f, "ReEarlyBound({}, {})", data.index, data.name),
83 ty::ReLateBound(binder_id, ref bound_region) => {
84 write!(f, "ReLateBound({:?}, {:?})", binder_id, bound_region)
87 ty::ReFree(ref fr) => fr.fmt(f),
89 ty::ReStatic => write!(f, "ReStatic"),
91 ty::ReVar(ref vid) => vid.fmt(f),
93 ty::RePlaceholder(placeholder) => write!(f, "RePlaceholder({:?})", placeholder),
95 ty::ReEmpty(ui) => write!(f, "ReEmpty({:?})", ui),
97 ty::ReErased => write!(f, "ReErased"),
102 impl fmt::Debug for ty::FreeRegion {
103 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
104 write!(f, "ReFree({:?}, {:?})", self.scope, self.bound_region)
108 impl<'tcx> fmt::Debug for ty::FnSig<'tcx> {
109 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
110 write!(f, "({:?}; c_variadic: {})->{:?}", self.inputs(), self.c_variadic, self.output())
114 impl<'tcx> fmt::Debug for ty::ConstVid<'tcx> {
115 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
116 write!(f, "_#{}c", self.index)
120 impl fmt::Debug for ty::RegionVid {
121 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
122 write!(f, "'_#{}r", self.index())
126 impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> {
127 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
128 with_no_trimmed_paths(|| fmt::Display::fmt(self, f))
132 impl<'tcx> fmt::Debug for Ty<'tcx> {
133 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
134 with_no_trimmed_paths(|| fmt::Display::fmt(self, f))
138 impl fmt::Debug for ty::ParamTy {
139 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
140 write!(f, "{}/#{}", self.name, self.index)
144 impl fmt::Debug for ty::ParamConst {
145 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
146 write!(f, "{}/#{}", self.name, self.index)
150 impl<'tcx> fmt::Debug for ty::TraitPredicate<'tcx> {
151 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
152 if let ty::BoundConstness::ConstIfConst = self.constness {
153 write!(f, "~const ")?;
155 write!(f, "TraitPredicate({:?}, polarity:{:?})", self.trait_ref, self.polarity)
159 impl<'tcx> fmt::Debug for ty::ProjectionPredicate<'tcx> {
160 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
161 write!(f, "ProjectionPredicate({:?}, {:?})", self.projection_ty, self.term)
165 impl<'tcx> fmt::Debug for ty::Predicate<'tcx> {
166 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
167 write!(f, "{:?}", self.kind())
171 impl<'tcx> fmt::Debug for ty::PredicateKind<'tcx> {
172 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
174 ty::PredicateKind::Trait(ref a) => a.fmt(f),
175 ty::PredicateKind::Subtype(ref pair) => pair.fmt(f),
176 ty::PredicateKind::Coerce(ref pair) => pair.fmt(f),
177 ty::PredicateKind::RegionOutlives(ref pair) => pair.fmt(f),
178 ty::PredicateKind::TypeOutlives(ref pair) => pair.fmt(f),
179 ty::PredicateKind::Projection(ref pair) => pair.fmt(f),
180 ty::PredicateKind::WellFormed(data) => write!(f, "WellFormed({:?})", data),
181 ty::PredicateKind::ObjectSafe(trait_def_id) => {
182 write!(f, "ObjectSafe({:?})", trait_def_id)
184 ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
185 write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind)
187 ty::PredicateKind::ConstEvaluatable(uv) => {
188 write!(f, "ConstEvaluatable({:?}, {:?})", uv.def, uv.substs)
190 ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
191 ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
192 write!(f, "TypeWellFormedFromEnv({:?})", ty)
198 ///////////////////////////////////////////////////////////////////////////
201 // For things that don't carry any arena-allocated data (and are
202 // copy...), just add them to this list.
204 TrivialTypeFoldableAndLiftImpls! {
208 ::rustc_target::abi::VariantIdx,
212 crate::middle::region::Scope,
214 ::rustc_ast::InlineAsmOptions,
215 ::rustc_ast::InlineAsmTemplatePiece,
217 ::rustc_span::symbol::Symbol,
218 ::rustc_hir::def::Res,
219 ::rustc_hir::def_id::DefId,
220 ::rustc_hir::def_id::LocalDefId,
222 ::rustc_hir::MatchSource,
223 ::rustc_hir::Mutability,
224 ::rustc_hir::Unsafety,
225 ::rustc_target::asm::InlineAsmRegOrRegClass,
226 ::rustc_target::spec::abi::Abi,
227 crate::mir::coverage::ExpressionOperandId,
228 crate::mir::coverage::CounterValueReference,
229 crate::mir::coverage::InjectedExpressionId,
230 crate::mir::coverage::InjectedExpressionIndex,
231 crate::mir::coverage::MappedExpressionIndex,
233 crate::mir::Promoted,
234 crate::traits::Reveal,
235 crate::ty::adjustment::AutoBorrowMutability,
237 crate::ty::BoundConstness,
238 // Including `BoundRegionKind` is a *bit* dubious, but direct
239 // references to bound region appear in `ty::Error`, and aren't
240 // really meant to be folded. In general, we can only fold a fully
242 crate::ty::BoundRegionKind,
243 crate::ty::AssocItem,
244 crate::ty::Placeholder<crate::ty::BoundRegionKind>,
245 crate::ty::ClosureKind,
246 crate::ty::FreeRegion,
248 crate::ty::IntVarValue,
249 crate::ty::ParamConst,
251 crate::ty::adjustment::PointerCast,
252 crate::ty::RegionVid,
253 crate::ty::UniverseIndex,
258 ///////////////////////////////////////////////////////////////////////////
259 // Lift implementations
261 // FIXME(eddyb) replace all the uses of `Option::map` with `?`.
262 impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>> Lift<'tcx> for (A, B) {
263 type Lifted = (A::Lifted, B::Lifted);
264 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
265 Some((tcx.lift(self.0)?, tcx.lift(self.1)?))
269 impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>, C: Lift<'tcx>> Lift<'tcx> for (A, B, C) {
270 type Lifted = (A::Lifted, B::Lifted, C::Lifted);
271 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
272 Some((tcx.lift(self.0)?, tcx.lift(self.1)?, tcx.lift(self.2)?))
276 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
277 type Lifted = Option<T::Lifted>;
278 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
280 Some(x) => tcx.lift(x).map(Some),
286 impl<'tcx, T: Lift<'tcx>, E: Lift<'tcx>> Lift<'tcx> for Result<T, E> {
287 type Lifted = Result<T::Lifted, E::Lifted>;
288 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
290 Ok(x) => tcx.lift(x).map(Ok),
291 Err(e) => tcx.lift(e).map(Err),
296 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Box<T> {
297 type Lifted = Box<T::Lifted>;
298 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
299 tcx.lift(*self).map(Box::new)
303 impl<'tcx, T: Lift<'tcx> + Clone> Lift<'tcx> for Rc<T> {
304 type Lifted = Rc<T::Lifted>;
305 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
306 tcx.lift(self.as_ref().clone()).map(Rc::new)
310 impl<'tcx, T: Lift<'tcx> + Clone> Lift<'tcx> for Arc<T> {
311 type Lifted = Arc<T::Lifted>;
312 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
313 tcx.lift(self.as_ref().clone()).map(Arc::new)
316 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Vec<T> {
317 type Lifted = Vec<T::Lifted>;
318 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
319 self.into_iter().map(|v| tcx.lift(v)).collect()
323 impl<'tcx, I: Idx, T: Lift<'tcx>> Lift<'tcx> for IndexVec<I, T> {
324 type Lifted = IndexVec<I, T::Lifted>;
325 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
326 self.into_iter().map(|e| tcx.lift(e)).collect()
330 impl<'a, 'tcx> Lift<'tcx> for ty::TraitRef<'a> {
331 type Lifted = ty::TraitRef<'tcx>;
332 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
333 tcx.lift(self.substs).map(|substs| ty::TraitRef { def_id: self.def_id, substs })
337 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialTraitRef<'a> {
338 type Lifted = ty::ExistentialTraitRef<'tcx>;
339 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
340 tcx.lift(self.substs).map(|substs| ty::ExistentialTraitRef { def_id: self.def_id, substs })
344 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialPredicate<'a> {
345 type Lifted = ty::ExistentialPredicate<'tcx>;
346 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
348 ty::ExistentialPredicate::Trait(x) => tcx.lift(x).map(ty::ExistentialPredicate::Trait),
349 ty::ExistentialPredicate::Projection(x) => {
350 tcx.lift(x).map(ty::ExistentialPredicate::Projection)
352 ty::ExistentialPredicate::AutoTrait(def_id) => {
353 Some(ty::ExistentialPredicate::AutoTrait(def_id))
359 impl<'a, 'tcx> Lift<'tcx> for Term<'a> {
360 type Lifted = ty::Term<'tcx>;
361 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
363 Term::Ty(ty) => Term::Ty(tcx.lift(ty)?),
364 Term::Const(c) => Term::Const(tcx.lift(c)?),
369 impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> {
370 type Lifted = ty::TraitPredicate<'tcx>;
371 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ty::TraitPredicate<'tcx>> {
372 tcx.lift(self.trait_ref).map(|trait_ref| ty::TraitPredicate {
374 constness: self.constness,
375 polarity: self.polarity,
380 impl<'a, 'tcx> Lift<'tcx> for ty::SubtypePredicate<'a> {
381 type Lifted = ty::SubtypePredicate<'tcx>;
382 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ty::SubtypePredicate<'tcx>> {
383 tcx.lift((self.a, self.b)).map(|(a, b)| ty::SubtypePredicate {
384 a_is_expected: self.a_is_expected,
391 impl<'a, 'tcx> Lift<'tcx> for ty::CoercePredicate<'a> {
392 type Lifted = ty::CoercePredicate<'tcx>;
393 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ty::CoercePredicate<'tcx>> {
394 tcx.lift((self.a, self.b)).map(|(a, b)| ty::CoercePredicate { a, b })
398 impl<'tcx, A: Copy + Lift<'tcx>, B: Copy + Lift<'tcx>> Lift<'tcx> for ty::OutlivesPredicate<A, B> {
399 type Lifted = ty::OutlivesPredicate<A::Lifted, B::Lifted>;
400 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
401 tcx.lift((self.0, self.1)).map(|(a, b)| ty::OutlivesPredicate(a, b))
405 impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionTy<'a> {
406 type Lifted = ty::ProjectionTy<'tcx>;
407 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ty::ProjectionTy<'tcx>> {
408 tcx.lift(self.substs)
409 .map(|substs| ty::ProjectionTy { item_def_id: self.item_def_id, substs })
413 impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionPredicate<'a> {
414 type Lifted = ty::ProjectionPredicate<'tcx>;
415 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ty::ProjectionPredicate<'tcx>> {
416 tcx.lift((self.projection_ty, self.term))
417 .map(|(projection_ty, term)| ty::ProjectionPredicate { projection_ty, term })
421 impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> {
422 type Lifted = ty::ExistentialProjection<'tcx>;
423 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
424 tcx.lift(self.substs).map(|substs| ty::ExistentialProjection {
426 term: tcx.lift(self.term).expect("type must lift when substs do"),
427 item_def_id: self.item_def_id,
432 impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
433 type Lifted = ty::PredicateKind<'tcx>;
434 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
436 ty::PredicateKind::Trait(data) => tcx.lift(data).map(ty::PredicateKind::Trait),
437 ty::PredicateKind::Subtype(data) => tcx.lift(data).map(ty::PredicateKind::Subtype),
438 ty::PredicateKind::Coerce(data) => tcx.lift(data).map(ty::PredicateKind::Coerce),
439 ty::PredicateKind::RegionOutlives(data) => {
440 tcx.lift(data).map(ty::PredicateKind::RegionOutlives)
442 ty::PredicateKind::TypeOutlives(data) => {
443 tcx.lift(data).map(ty::PredicateKind::TypeOutlives)
445 ty::PredicateKind::Projection(data) => {
446 tcx.lift(data).map(ty::PredicateKind::Projection)
448 ty::PredicateKind::WellFormed(ty) => tcx.lift(ty).map(ty::PredicateKind::WellFormed),
449 ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
450 tcx.lift(closure_substs).map(|closure_substs| {
451 ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind)
454 ty::PredicateKind::ObjectSafe(trait_def_id) => {
455 Some(ty::PredicateKind::ObjectSafe(trait_def_id))
457 ty::PredicateKind::ConstEvaluatable(uv) => {
458 tcx.lift(uv).map(|uv| ty::PredicateKind::ConstEvaluatable(uv))
460 ty::PredicateKind::ConstEquate(c1, c2) => {
461 tcx.lift((c1, c2)).map(|(c1, c2)| ty::PredicateKind::ConstEquate(c1, c2))
463 ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
464 tcx.lift(ty).map(ty::PredicateKind::TypeWellFormedFromEnv)
470 impl<'a, 'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<'a, T>
472 <T as Lift<'tcx>>::Lifted: TypeFoldable<'tcx>,
474 type Lifted = ty::Binder<'tcx, T::Lifted>;
475 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
476 let bound_vars = tcx.lift(self.bound_vars());
477 tcx.lift(self.skip_binder())
479 .map(|(value, vars)| ty::Binder::bind_with_vars(value, vars))
483 impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> {
484 type Lifted = ty::ParamEnv<'tcx>;
485 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
486 tcx.lift(self.caller_bounds())
487 .map(|caller_bounds| ty::ParamEnv::new(caller_bounds, self.reveal(), self.constness()))
491 impl<'a, 'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::ParamEnvAnd<'a, T> {
492 type Lifted = ty::ParamEnvAnd<'tcx, T::Lifted>;
493 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
494 tcx.lift(self.param_env).and_then(|param_env| {
495 tcx.lift(self.value).map(|value| ty::ParamEnvAnd { param_env, value })
500 impl<'a, 'tcx> Lift<'tcx> for ty::ClosureSubsts<'a> {
501 type Lifted = ty::ClosureSubsts<'tcx>;
502 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
503 tcx.lift(self.substs).map(|substs| ty::ClosureSubsts { substs })
507 impl<'a, 'tcx> Lift<'tcx> for ty::GeneratorSubsts<'a> {
508 type Lifted = ty::GeneratorSubsts<'tcx>;
509 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
510 tcx.lift(self.substs).map(|substs| ty::GeneratorSubsts { substs })
514 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjustment<'a> {
515 type Lifted = ty::adjustment::Adjustment<'tcx>;
516 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
517 let ty::adjustment::Adjustment { kind, target } = self;
518 tcx.lift(kind).and_then(|kind| {
519 tcx.lift(target).map(|target| ty::adjustment::Adjustment { kind, target })
524 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
525 type Lifted = ty::adjustment::Adjust<'tcx>;
526 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
528 ty::adjustment::Adjust::NeverToAny => Some(ty::adjustment::Adjust::NeverToAny),
529 ty::adjustment::Adjust::Pointer(ptr) => Some(ty::adjustment::Adjust::Pointer(ptr)),
530 ty::adjustment::Adjust::Deref(overloaded) => {
531 tcx.lift(overloaded).map(ty::adjustment::Adjust::Deref)
533 ty::adjustment::Adjust::Borrow(autoref) => {
534 tcx.lift(autoref).map(ty::adjustment::Adjust::Borrow)
540 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::OverloadedDeref<'a> {
541 type Lifted = ty::adjustment::OverloadedDeref<'tcx>;
542 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
543 tcx.lift(self.region).map(|region| ty::adjustment::OverloadedDeref {
551 impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> {
552 type Lifted = ty::adjustment::AutoBorrow<'tcx>;
553 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
555 ty::adjustment::AutoBorrow::Ref(r, m) => {
556 tcx.lift(r).map(|r| ty::adjustment::AutoBorrow::Ref(r, m))
558 ty::adjustment::AutoBorrow::RawPtr(m) => Some(ty::adjustment::AutoBorrow::RawPtr(m)),
563 impl<'a, 'tcx> Lift<'tcx> for ty::GenSig<'a> {
564 type Lifted = ty::GenSig<'tcx>;
565 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
566 tcx.lift((self.resume_ty, self.yield_ty, self.return_ty))
567 .map(|(resume_ty, yield_ty, return_ty)| ty::GenSig { resume_ty, yield_ty, return_ty })
571 impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> {
572 type Lifted = ty::FnSig<'tcx>;
573 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
574 tcx.lift(self.inputs_and_output).map(|x| ty::FnSig {
575 inputs_and_output: x,
576 c_variadic: self.c_variadic,
577 unsafety: self.unsafety,
583 impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::error::ExpectedFound<T> {
584 type Lifted = ty::error::ExpectedFound<T::Lifted>;
585 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
586 let ty::error::ExpectedFound { expected, found } = self;
587 tcx.lift(expected).and_then(|expected| {
588 tcx.lift(found).map(|found| ty::error::ExpectedFound { expected, found })
593 impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
594 type Lifted = ty::error::TypeError<'tcx>;
595 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
596 use crate::ty::error::TypeError::*;
599 Mismatch => Mismatch,
600 ConstnessMismatch(x) => ConstnessMismatch(x),
601 PolarityMismatch(x) => PolarityMismatch(x),
602 UnsafetyMismatch(x) => UnsafetyMismatch(x),
603 AbiMismatch(x) => AbiMismatch(x),
604 Mutability => Mutability,
605 ArgumentMutability(i) => ArgumentMutability(i),
606 TupleSize(x) => TupleSize(x),
607 FixedArraySize(x) => FixedArraySize(x),
608 ArgCount => ArgCount,
609 FieldMisMatch(x, y) => FieldMisMatch(x, y),
610 RegionsDoesNotOutlive(a, b) => {
611 return tcx.lift((a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b));
613 RegionsInsufficientlyPolymorphic(a, b) => {
614 return tcx.lift(b).map(|b| RegionsInsufficientlyPolymorphic(a, b));
616 RegionsOverlyPolymorphic(a, b) => {
617 return tcx.lift(b).map(|b| RegionsOverlyPolymorphic(a, b));
619 RegionsPlaceholderMismatch => RegionsPlaceholderMismatch,
620 IntMismatch(x) => IntMismatch(x),
621 FloatMismatch(x) => FloatMismatch(x),
622 Traits(x) => Traits(x),
623 VariadicMismatch(x) => VariadicMismatch(x),
624 CyclicTy(t) => return tcx.lift(t).map(|t| CyclicTy(t)),
625 CyclicConst(ct) => return tcx.lift(ct).map(|ct| CyclicConst(ct)),
626 ProjectionMismatched(x) => ProjectionMismatched(x),
627 ArgumentSorts(x, i) => return tcx.lift(x).map(|x| ArgumentSorts(x, i)),
628 Sorts(x) => return tcx.lift(x).map(Sorts),
629 ExistentialMismatch(x) => return tcx.lift(x).map(ExistentialMismatch),
630 ConstMismatch(x) => return tcx.lift(x).map(ConstMismatch),
631 IntrinsicCast => IntrinsicCast,
632 TargetFeatureCast(x) => TargetFeatureCast(x),
633 ObjectUnsafeCoercion(x) => return tcx.lift(x).map(ObjectUnsafeCoercion),
638 impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
639 type Lifted = ty::InstanceDef<'tcx>;
640 fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
642 ty::InstanceDef::Item(def_id) => Some(ty::InstanceDef::Item(def_id)),
643 ty::InstanceDef::VtableShim(def_id) => Some(ty::InstanceDef::VtableShim(def_id)),
644 ty::InstanceDef::ReifyShim(def_id) => Some(ty::InstanceDef::ReifyShim(def_id)),
645 ty::InstanceDef::Intrinsic(def_id) => Some(ty::InstanceDef::Intrinsic(def_id)),
646 ty::InstanceDef::FnPtrShim(def_id, ty) => {
647 Some(ty::InstanceDef::FnPtrShim(def_id, tcx.lift(ty)?))
649 ty::InstanceDef::Virtual(def_id, n) => Some(ty::InstanceDef::Virtual(def_id, n)),
650 ty::InstanceDef::ClosureOnceShim { call_once, track_caller } => {
651 Some(ty::InstanceDef::ClosureOnceShim { call_once, track_caller })
653 ty::InstanceDef::DropGlue(def_id, ty) => {
654 Some(ty::InstanceDef::DropGlue(def_id, tcx.lift(ty)?))
656 ty::InstanceDef::CloneShim(def_id, ty) => {
657 Some(ty::InstanceDef::CloneShim(def_id, tcx.lift(ty)?))
663 ///////////////////////////////////////////////////////////////////////////
664 // TypeFoldable implementations.
666 // Ideally, each type should invoke `folder.fold_foo(self)` and
667 // nothing else. In some cases, though, we haven't gotten around to
668 // adding methods on the `folder` yet, and thus the folding is
669 // hard-coded here. This is less-flexible, because folders cannot
670 // override the behavior, but there are a lot of random types and one
671 // can easily refactor the folding into the TypeFolder trait as
674 /// AdtDefs are basically the same as a DefId.
675 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::AdtDef {
676 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
679 ) -> Result<Self, F::Error> {
683 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<V::BreakTy> {
684 ControlFlow::CONTINUE
688 impl<'tcx, T: TypeFoldable<'tcx>, U: TypeFoldable<'tcx>> TypeFoldable<'tcx> for (T, U) {
689 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
692 ) -> Result<(T, U), F::Error> {
693 Ok((self.0.try_fold_with(folder)?, self.1.try_fold_with(folder)?))
696 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
697 self.0.visit_with(visitor)?;
698 self.1.visit_with(visitor)
702 impl<'tcx, A: TypeFoldable<'tcx>, B: TypeFoldable<'tcx>, C: TypeFoldable<'tcx>> TypeFoldable<'tcx>
705 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
708 ) -> Result<(A, B, C), F::Error> {
710 self.0.try_fold_with(folder)?,
711 self.1.try_fold_with(folder)?,
712 self.2.try_fold_with(folder)?,
716 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
717 self.0.visit_with(visitor)?;
718 self.1.visit_with(visitor)?;
719 self.2.visit_with(visitor)
723 EnumTypeFoldableImpl! {
724 impl<'tcx, T> TypeFoldable<'tcx> for Option<T> {
727 } where T: TypeFoldable<'tcx>
730 EnumTypeFoldableImpl! {
731 impl<'tcx, T, E> TypeFoldable<'tcx> for Result<T, E> {
734 } where T: TypeFoldable<'tcx>, E: TypeFoldable<'tcx>,
737 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
738 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
741 ) -> Result<Self, F::Error> {
742 // We merely want to replace the contained `T`, if at all possible,
743 // so that we don't needlessly allocate a new `Rc` or indeed clone
744 // the contained type.
746 // First step is to ensure that we have a unique reference to
747 // the contained type, which `Rc::make_mut` will accomplish (by
748 // allocating a new `Rc` and cloning the `T` only if required).
749 // This is done *before* casting to `Rc<ManuallyDrop<T>>` so that
750 // panicking during `make_mut` does not leak the `T`.
751 Rc::make_mut(&mut self);
753 // Casting to `Rc<ManuallyDrop<T>>` is safe because `ManuallyDrop`
754 // is `repr(transparent)`.
755 let ptr = Rc::into_raw(self).cast::<ManuallyDrop<T>>();
756 let mut unique = Rc::from_raw(ptr);
758 // Call to `Rc::make_mut` above guarantees that `unique` is the
759 // sole reference to the contained value, so we can avoid doing
760 // a checked `get_mut` here.
761 let slot = Rc::get_mut_unchecked(&mut unique);
763 // Semantically move the contained type out from `unique`, fold
764 // it, then move the folded value back into `unique`. Should
765 // folding fail, `ManuallyDrop` ensures that the "moved-out"
766 // value is not re-dropped.
767 let owned = ManuallyDrop::take(slot);
768 let folded = owned.try_fold_with(folder)?;
769 *slot = ManuallyDrop::new(folded);
771 // Cast back to `Rc<T>`.
772 Ok(Rc::from_raw(Rc::into_raw(unique).cast()))
776 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
777 (**self).visit_with(visitor)
781 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Arc<T> {
782 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
785 ) -> Result<Self, F::Error> {
786 // We merely want to replace the contained `T`, if at all possible,
787 // so that we don't needlessly allocate a new `Arc` or indeed clone
788 // the contained type.
790 // First step is to ensure that we have a unique reference to
791 // the contained type, which `Arc::make_mut` will accomplish (by
792 // allocating a new `Arc` and cloning the `T` only if required).
793 // This is done *before* casting to `Arc<ManuallyDrop<T>>` so that
794 // panicking during `make_mut` does not leak the `T`.
795 Arc::make_mut(&mut self);
797 // Casting to `Arc<ManuallyDrop<T>>` is safe because `ManuallyDrop`
798 // is `repr(transparent)`.
799 let ptr = Arc::into_raw(self).cast::<ManuallyDrop<T>>();
800 let mut unique = Arc::from_raw(ptr);
802 // Call to `Arc::make_mut` above guarantees that `unique` is the
803 // sole reference to the contained value, so we can avoid doing
804 // a checked `get_mut` here.
805 let slot = Arc::get_mut_unchecked(&mut unique);
807 // Semantically move the contained type out from `unique`, fold
808 // it, then move the folded value back into `unique`. Should
809 // folding fail, `ManuallyDrop` ensures that the "moved-out"
810 // value is not re-dropped.
811 let owned = ManuallyDrop::take(slot);
812 let folded = owned.try_fold_with(folder)?;
813 *slot = ManuallyDrop::new(folded);
815 // Cast back to `Arc<T>`.
816 Ok(Arc::from_raw(Arc::into_raw(unique).cast()))
820 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
821 (**self).visit_with(visitor)
825 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> {
826 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
829 ) -> Result<Self, F::Error> {
830 self.try_map_id(|value| value.try_fold_with(folder))
833 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
834 (**self).visit_with(visitor)
838 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
839 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
842 ) -> Result<Self, F::Error> {
843 self.try_map_id(|t| t.try_fold_with(folder))
846 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
847 self.iter().try_for_each(|t| t.visit_with(visitor))
851 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> {
852 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
855 ) -> Result<Self, F::Error> {
856 self.try_map_id(|t| t.try_fold_with(folder))
859 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
860 self.iter().try_for_each(|t| t.visit_with(visitor))
864 impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<'tcx, T> {
865 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
868 ) -> Result<Self, F::Error> {
869 self.try_map_bound(|ty| ty.try_fold_with(folder))
872 fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
873 folder.try_fold_binder(self)
876 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
877 self.as_ref().skip_binder().visit_with(visitor)
880 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
881 visitor.visit_binder(self)
885 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>> {
886 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
889 ) -> Result<Self, F::Error> {
890 ty::util::fold_list(self, folder, |tcx, v| tcx.intern_poly_existential_predicates(v))
893 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
894 self.iter().try_for_each(|p| p.visit_with(visitor))
898 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
899 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
902 ) -> Result<Self, F::Error> {
903 ty::util::fold_list(self, folder, |tcx, v| tcx.intern_type_list(v))
906 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
907 self.iter().try_for_each(|t| t.visit_with(visitor))
911 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> {
912 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
915 ) -> Result<Self, F::Error> {
916 ty::util::fold_list(self, folder, |tcx, v| tcx.intern_projs(v))
919 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
920 self.iter().try_for_each(|t| t.visit_with(visitor))
924 impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> {
925 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
928 ) -> Result<Self, F::Error> {
929 use crate::ty::InstanceDef::*;
931 substs: self.substs.try_fold_with(folder)?,
932 def: match self.def {
933 Item(def) => Item(def.try_fold_with(folder)?),
934 VtableShim(did) => VtableShim(did.try_fold_with(folder)?),
935 ReifyShim(did) => ReifyShim(did.try_fold_with(folder)?),
936 Intrinsic(did) => Intrinsic(did.try_fold_with(folder)?),
937 FnPtrShim(did, ty) => {
938 FnPtrShim(did.try_fold_with(folder)?, ty.try_fold_with(folder)?)
940 Virtual(did, i) => Virtual(did.try_fold_with(folder)?, i),
941 ClosureOnceShim { call_once, track_caller } => {
942 ClosureOnceShim { call_once: call_once.try_fold_with(folder)?, track_caller }
944 DropGlue(did, ty) => {
945 DropGlue(did.try_fold_with(folder)?, ty.try_fold_with(folder)?)
947 CloneShim(did, ty) => {
948 CloneShim(did.try_fold_with(folder)?, ty.try_fold_with(folder)?)
954 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
955 use crate::ty::InstanceDef::*;
956 self.substs.visit_with(visitor)?;
958 Item(def) => def.visit_with(visitor),
959 VtableShim(did) | ReifyShim(did) | Intrinsic(did) | Virtual(did, _) => {
960 did.visit_with(visitor)
962 FnPtrShim(did, ty) | CloneShim(did, ty) => {
963 did.visit_with(visitor)?;
964 ty.visit_with(visitor)
966 DropGlue(did, ty) => {
967 did.visit_with(visitor)?;
968 ty.visit_with(visitor)
970 ClosureOnceShim { call_once, track_caller: _ } => call_once.visit_with(visitor),
975 impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'tcx> {
976 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
979 ) -> Result<Self, F::Error> {
980 Ok(Self { instance: self.instance.try_fold_with(folder)?, promoted: self.promoted })
983 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
984 self.instance.visit_with(visitor)
988 impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
989 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
992 ) -> Result<Self, F::Error> {
993 let kind = match *self.kind() {
994 ty::RawPtr(tm) => ty::RawPtr(tm.try_fold_with(folder)?),
995 ty::Array(typ, sz) => ty::Array(typ.try_fold_with(folder)?, sz.try_fold_with(folder)?),
996 ty::Slice(typ) => ty::Slice(typ.try_fold_with(folder)?),
997 ty::Adt(tid, substs) => ty::Adt(tid, substs.try_fold_with(folder)?),
998 ty::Dynamic(trait_ty, region) => {
999 ty::Dynamic(trait_ty.try_fold_with(folder)?, region.try_fold_with(folder)?)
1001 ty::Tuple(ts) => ty::Tuple(ts.try_fold_with(folder)?),
1002 ty::FnDef(def_id, substs) => ty::FnDef(def_id, substs.try_fold_with(folder)?),
1003 ty::FnPtr(f) => ty::FnPtr(f.try_fold_with(folder)?),
1004 ty::Ref(r, ty, mutbl) => {
1005 ty::Ref(r.try_fold_with(folder)?, ty.try_fold_with(folder)?, mutbl)
1007 ty::Generator(did, substs, movability) => {
1008 ty::Generator(did, substs.try_fold_with(folder)?, movability)
1010 ty::GeneratorWitness(types) => ty::GeneratorWitness(types.try_fold_with(folder)?),
1011 ty::Closure(did, substs) => ty::Closure(did, substs.try_fold_with(folder)?),
1012 ty::Projection(data) => ty::Projection(data.try_fold_with(folder)?),
1013 ty::Opaque(did, substs) => ty::Opaque(did, substs.try_fold_with(folder)?),
1025 | ty::Placeholder(..)
1027 | ty::Foreign(..) => return Ok(self),
1030 Ok(if *self.kind() == kind { self } else { folder.tcx().mk_ty(kind) })
1033 fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
1034 folder.try_fold_ty(self)
1037 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1039 ty::RawPtr(ref tm) => tm.visit_with(visitor),
1040 ty::Array(typ, sz) => {
1041 typ.visit_with(visitor)?;
1042 sz.visit_with(visitor)
1044 ty::Slice(typ) => typ.visit_with(visitor),
1045 ty::Adt(_, substs) => substs.visit_with(visitor),
1046 ty::Dynamic(ref trait_ty, ref reg) => {
1047 trait_ty.visit_with(visitor)?;
1048 reg.visit_with(visitor)
1050 ty::Tuple(ts) => ts.visit_with(visitor),
1051 ty::FnDef(_, substs) => substs.visit_with(visitor),
1052 ty::FnPtr(ref f) => f.visit_with(visitor),
1053 ty::Ref(r, ty, _) => {
1054 r.visit_with(visitor)?;
1055 ty.visit_with(visitor)
1057 ty::Generator(_did, ref substs, _) => substs.visit_with(visitor),
1058 ty::GeneratorWitness(ref types) => types.visit_with(visitor),
1059 ty::Closure(_did, ref substs) => substs.visit_with(visitor),
1060 ty::Projection(ref data) => data.visit_with(visitor),
1061 ty::Opaque(_, ref substs) => substs.visit_with(visitor),
1072 | ty::Placeholder(..)
1075 | ty::Foreign(..) => ControlFlow::CONTINUE,
1079 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1080 visitor.visit_ty(self)
1084 impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
1085 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
1088 ) -> Result<Self, F::Error> {
1092 fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
1093 folder.try_fold_region(self)
1096 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<V::BreakTy> {
1097 ControlFlow::CONTINUE
1100 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1101 visitor.visit_region(*self)
1105 impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
1106 fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
1107 folder.try_fold_predicate(self)
1110 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
1113 ) -> Result<Self, F::Error> {
1114 let new = self.inner.kind.try_fold_with(folder)?;
1115 Ok(folder.tcx().reuse_or_mk_predicate(self, new))
1118 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1119 self.inner.kind.visit_with(visitor)
1122 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1123 visitor.visit_predicate(*self)
1126 fn has_vars_bound_at_or_above(&self, binder: ty::DebruijnIndex) -> bool {
1127 self.inner.outer_exclusive_binder > binder
1130 fn has_type_flags(&self, flags: ty::TypeFlags) -> bool {
1131 self.inner.flags.intersects(flags)
1135 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
1136 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
1139 ) -> Result<Self, F::Error> {
1140 ty::util::fold_list(self, folder, |tcx, v| tcx.intern_predicates(v))
1143 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1144 self.iter().try_for_each(|p| p.visit_with(visitor))
1148 impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T> {
1149 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
1152 ) -> Result<Self, F::Error> {
1153 self.try_map_id(|x| x.try_fold_with(folder))
1156 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1157 self.iter().try_for_each(|t| t.visit_with(visitor))
1161 impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Const<'tcx> {
1162 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
1165 ) -> Result<Self, F::Error> {
1166 let ty = self.ty.try_fold_with(folder)?;
1167 let val = self.val.try_fold_with(folder)?;
1168 if ty != self.ty || val != self.val {
1169 Ok(folder.tcx().mk_const(ty::Const { ty, val }))
1175 fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
1176 folder.try_fold_const(self)
1179 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1180 self.ty.visit_with(visitor)?;
1181 self.val.visit_with(visitor)
1184 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1185 visitor.visit_const(self)
1189 impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> {
1190 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
1193 ) -> Result<Self, F::Error> {
1195 ty::ConstKind::Infer(ic) => ty::ConstKind::Infer(ic.try_fold_with(folder)?),
1196 ty::ConstKind::Param(p) => ty::ConstKind::Param(p.try_fold_with(folder)?),
1197 ty::ConstKind::Unevaluated(uv) => ty::ConstKind::Unevaluated(uv.try_fold_with(folder)?),
1198 ty::ConstKind::Value(_)
1199 | ty::ConstKind::Bound(..)
1200 | ty::ConstKind::Placeholder(..)
1201 | ty::ConstKind::Error(_) => self,
1205 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1207 ty::ConstKind::Infer(ic) => ic.visit_with(visitor),
1208 ty::ConstKind::Param(p) => p.visit_with(visitor),
1209 ty::ConstKind::Unevaluated(uv) => uv.visit_with(visitor),
1210 ty::ConstKind::Value(_)
1211 | ty::ConstKind::Bound(..)
1212 | ty::ConstKind::Placeholder(_)
1213 | ty::ConstKind::Error(_) => ControlFlow::CONTINUE,
1218 impl<'tcx> TypeFoldable<'tcx> for InferConst<'tcx> {
1219 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
1222 ) -> Result<Self, F::Error> {
1226 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<V::BreakTy> {
1227 ControlFlow::CONTINUE
1231 impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx> {
1232 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
1235 ) -> Result<Self, F::Error> {
1236 Ok(ty::Unevaluated {
1238 substs: self.substs.try_fold_with(folder)?,
1239 promoted: self.promoted,
1243 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1244 visitor.visit_unevaluated_const(*self)
1247 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1248 self.substs.visit_with(visitor)
1252 impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx, ()> {
1253 fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
1256 ) -> Result<Self, F::Error> {
1257 Ok(ty::Unevaluated {
1259 substs: self.substs.try_fold_with(folder)?,
1260 promoted: self.promoted,
1264 fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1265 visitor.visit_unevaluated_const(self.expand())
1268 fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
1269 self.substs.visit_with(visitor)