1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use infer
::type_variable
;
12 use middle
::const_val
::{self, ConstVal, ConstAggregate, ConstEvalErr}
;
13 use ty
::{self, Lift, Ty, TyCtxt}
;
14 use ty
::fold
::{TypeFoldable, TypeFolder, TypeVisitor}
;
15 use rustc_data_structures
::accumulate_vec
::AccumulateVec
;
16 use rustc_data_structures
::indexed_vec
::{IndexVec, Idx}
;
23 ///////////////////////////////////////////////////////////////////////////
24 // Lift implementations
26 impl<'tcx
, A
: Lift
<'tcx
>, B
: Lift
<'tcx
>> Lift
<'tcx
> for (A
, B
) {
27 type Lifted
= (A
::Lifted
, B
::Lifted
);
28 fn lift_to_tcx
<'a
, 'gcx
>(&self, tcx
: TyCtxt
<'a
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
29 tcx
.lift(&self.0).and_then(|a
| tcx
.lift(&self.1).map(|b
| (a
, b
)))
33 impl<'tcx
, A
: Lift
<'tcx
>, B
: Lift
<'tcx
>, C
: Lift
<'tcx
>> Lift
<'tcx
> for (A
, B
, C
) {
34 type Lifted
= (A
::Lifted
, B
::Lifted
, C
::Lifted
);
35 fn lift_to_tcx
<'a
, 'gcx
>(&self, tcx
: TyCtxt
<'a
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
36 tcx
.lift(&self.0).and_then(|a
| {
37 tcx
.lift(&self.1).and_then(|b
| tcx
.lift(&self.2).map(|c
| (a
, b
, c
)))
42 impl<'tcx
, T
: Lift
<'tcx
>> Lift
<'tcx
> for Option
<T
> {
43 type Lifted
= Option
<T
::Lifted
>;
44 fn lift_to_tcx
<'a
, 'gcx
>(&self, tcx
: TyCtxt
<'a
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
46 Some(ref x
) => tcx
.lift(x
).map(Some
),
52 impl<'tcx
, T
: Lift
<'tcx
>, E
: Lift
<'tcx
>> Lift
<'tcx
> for Result
<T
, E
> {
53 type Lifted
= Result
<T
::Lifted
, E
::Lifted
>;
54 fn lift_to_tcx
<'a
, 'gcx
>(&self, tcx
: TyCtxt
<'a
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
56 Ok(ref x
) => tcx
.lift(x
).map(Ok
),
57 Err(ref e
) => tcx
.lift(e
).map(Err
)
62 impl<'tcx
, T
: Lift
<'tcx
>> Lift
<'tcx
> for Box
<T
> {
63 type Lifted
= Box
<T
::Lifted
>;
64 fn lift_to_tcx
<'a
, 'gcx
>(&self, tcx
: TyCtxt
<'a
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
65 tcx
.lift(&**self).map(Box
::new
)
69 impl<'tcx
, T
: Lift
<'tcx
>> Lift
<'tcx
> for [T
] {
70 type Lifted
= Vec
<T
::Lifted
>;
71 fn lift_to_tcx
<'a
, 'gcx
>(&self, tcx
: TyCtxt
<'a
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
72 // type annotation needed to inform `projection_must_outlive`
73 let mut result
: Vec
<<T
as Lift
<'tcx
>>::Lifted
>
74 = Vec
::with_capacity(self.len());
76 if let Some(value
) = tcx
.lift(x
) {
86 impl<'tcx
, T
: Lift
<'tcx
>> Lift
<'tcx
> for Vec
<T
> {
87 type Lifted
= Vec
<T
::Lifted
>;
88 fn lift_to_tcx
<'a
, 'gcx
>(&self, tcx
: TyCtxt
<'a
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
93 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::TraitRef
<'a
> {
94 type Lifted
= ty
::TraitRef
<'tcx
>;
95 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
96 tcx
.lift(&self.substs
).map(|substs
| ty
::TraitRef
{
103 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::ExistentialTraitRef
<'a
> {
104 type Lifted
= ty
::ExistentialTraitRef
<'tcx
>;
105 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
106 tcx
.lift(&self.substs
).map(|substs
| ty
::ExistentialTraitRef
{
113 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::TraitPredicate
<'a
> {
114 type Lifted
= ty
::TraitPredicate
<'tcx
>;
115 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>)
116 -> Option
<ty
::TraitPredicate
<'tcx
>> {
117 tcx
.lift(&self.trait_ref
).map(|trait_ref
| ty
::TraitPredicate
{
123 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::EquatePredicate
<'a
> {
124 type Lifted
= ty
::EquatePredicate
<'tcx
>;
125 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>)
126 -> Option
<ty
::EquatePredicate
<'tcx
>> {
127 tcx
.lift(&(self.0, self.1)).map(|(a
, b
)| ty
::EquatePredicate(a
, b
))
131 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::SubtypePredicate
<'a
> {
132 type Lifted
= ty
::SubtypePredicate
<'tcx
>;
133 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>)
134 -> Option
<ty
::SubtypePredicate
<'tcx
>> {
135 tcx
.lift(&(self.a
, self.b
)).map(|(a
, b
)| ty
::SubtypePredicate
{
136 a_is_expected
: self.a_is_expected
,
143 impl<'tcx
, A
: Copy
+Lift
<'tcx
>, B
: Copy
+Lift
<'tcx
>> Lift
<'tcx
> for ty
::OutlivesPredicate
<A
, B
> {
144 type Lifted
= ty
::OutlivesPredicate
<A
::Lifted
, B
::Lifted
>;
145 fn lift_to_tcx
<'a
, 'gcx
>(&self, tcx
: TyCtxt
<'a
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
146 tcx
.lift(&(self.0, self.1)).map(|(a
, b
)| ty
::OutlivesPredicate(a
, b
))
150 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::ProjectionTy
<'a
> {
151 type Lifted
= ty
::ProjectionTy
<'tcx
>;
152 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>)
153 -> Option
<ty
::ProjectionTy
<'tcx
>> {
154 tcx
.lift(&self.substs
).map(|substs
| {
156 item_def_id
: self.item_def_id
,
163 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::ProjectionPredicate
<'a
> {
164 type Lifted
= ty
::ProjectionPredicate
<'tcx
>;
165 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>)
166 -> Option
<ty
::ProjectionPredicate
<'tcx
>> {
167 tcx
.lift(&(self.projection_ty
, self.ty
)).map(|(projection_ty
, ty
)| {
168 ty
::ProjectionPredicate
{
176 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::ExistentialProjection
<'a
> {
177 type Lifted
= ty
::ExistentialProjection
<'tcx
>;
178 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
179 tcx
.lift(&self.substs
).map(|substs
| {
180 ty
::ExistentialProjection
{
182 ty
: tcx
.lift(&self.ty
).expect("type must lift when substs do"),
183 item_def_id
: self.item_def_id
,
189 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::Predicate
<'a
> {
190 type Lifted
= ty
::Predicate
<'tcx
>;
191 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
193 ty
::Predicate
::Trait(ref binder
) => {
194 tcx
.lift(binder
).map(ty
::Predicate
::Trait
)
196 ty
::Predicate
::Equate(ref binder
) => {
197 tcx
.lift(binder
).map(ty
::Predicate
::Equate
)
199 ty
::Predicate
::Subtype(ref binder
) => {
200 tcx
.lift(binder
).map(ty
::Predicate
::Subtype
)
202 ty
::Predicate
::RegionOutlives(ref binder
) => {
203 tcx
.lift(binder
).map(ty
::Predicate
::RegionOutlives
)
205 ty
::Predicate
::TypeOutlives(ref binder
) => {
206 tcx
.lift(binder
).map(ty
::Predicate
::TypeOutlives
)
208 ty
::Predicate
::Projection(ref binder
) => {
209 tcx
.lift(binder
).map(ty
::Predicate
::Projection
)
211 ty
::Predicate
::WellFormed(ty
) => {
212 tcx
.lift(&ty
).map(ty
::Predicate
::WellFormed
)
214 ty
::Predicate
::ClosureKind(closure_def_id
, kind
) => {
215 Some(ty
::Predicate
::ClosureKind(closure_def_id
, kind
))
217 ty
::Predicate
::ObjectSafe(trait_def_id
) => {
218 Some(ty
::Predicate
::ObjectSafe(trait_def_id
))
220 ty
::Predicate
::ConstEvaluatable(def_id
, substs
) => {
221 tcx
.lift(&substs
).map(|substs
| {
222 ty
::Predicate
::ConstEvaluatable(def_id
, substs
)
229 impl<'tcx
, T
: Lift
<'tcx
>> Lift
<'tcx
> for ty
::Binder
<T
> {
230 type Lifted
= ty
::Binder
<T
::Lifted
>;
231 fn lift_to_tcx
<'a
, 'gcx
>(&self, tcx
: TyCtxt
<'a
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
232 tcx
.lift(&self.0).map(|x
| ty
::Binder(x
))
236 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::ParamEnv
<'a
> {
237 type Lifted
= ty
::ParamEnv
<'tcx
>;
238 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
239 tcx
.lift(&self.caller_bounds
).map(|caller_bounds
| {
248 impl<'a
, 'tcx
, T
: Lift
<'tcx
>> Lift
<'tcx
> for ty
::ParamEnvAnd
<'a
, T
> {
249 type Lifted
= ty
::ParamEnvAnd
<'tcx
, T
::Lifted
>;
250 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
251 tcx
.lift(&self.param_env
).and_then(|param_env
| {
252 tcx
.lift(&self.value
).map(|value
| {
262 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::ClosureSubsts
<'a
> {
263 type Lifted
= ty
::ClosureSubsts
<'tcx
>;
264 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
265 tcx
.lift(&self.substs
).map(|substs
| {
266 ty
::ClosureSubsts { substs: substs }
271 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::GeneratorInterior
<'a
> {
272 type Lifted
= ty
::GeneratorInterior
<'tcx
>;
273 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
274 tcx
.lift(&self.witness
).map(|witness
| {
275 ty
::GeneratorInterior { witness }
280 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::adjustment
::Adjustment
<'a
> {
281 type Lifted
= ty
::adjustment
::Adjustment
<'tcx
>;
282 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
283 tcx
.lift(&self.kind
).and_then(|kind
| {
284 tcx
.lift(&self.target
).map(|target
| {
285 ty
::adjustment
::Adjustment { kind, target }
291 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::adjustment
::Adjust
<'a
> {
292 type Lifted
= ty
::adjustment
::Adjust
<'tcx
>;
293 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
295 ty
::adjustment
::Adjust
::NeverToAny
=>
296 Some(ty
::adjustment
::Adjust
::NeverToAny
),
297 ty
::adjustment
::Adjust
::ReifyFnPointer
=>
298 Some(ty
::adjustment
::Adjust
::ReifyFnPointer
),
299 ty
::adjustment
::Adjust
::UnsafeFnPointer
=>
300 Some(ty
::adjustment
::Adjust
::UnsafeFnPointer
),
301 ty
::adjustment
::Adjust
::ClosureFnPointer
=>
302 Some(ty
::adjustment
::Adjust
::ClosureFnPointer
),
303 ty
::adjustment
::Adjust
::MutToConstPointer
=>
304 Some(ty
::adjustment
::Adjust
::MutToConstPointer
),
305 ty
::adjustment
::Adjust
::Unsize
=>
306 Some(ty
::adjustment
::Adjust
::Unsize
),
307 ty
::adjustment
::Adjust
::Deref(ref overloaded
) => {
308 tcx
.lift(overloaded
).map(ty
::adjustment
::Adjust
::Deref
)
310 ty
::adjustment
::Adjust
::Borrow(ref autoref
) => {
311 tcx
.lift(autoref
).map(ty
::adjustment
::Adjust
::Borrow
)
317 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::adjustment
::OverloadedDeref
<'a
> {
318 type Lifted
= ty
::adjustment
::OverloadedDeref
<'tcx
>;
319 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
320 tcx
.lift(&self.region
).map(|region
| {
321 ty
::adjustment
::OverloadedDeref
{
329 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::adjustment
::AutoBorrow
<'a
> {
330 type Lifted
= ty
::adjustment
::AutoBorrow
<'tcx
>;
331 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
333 ty
::adjustment
::AutoBorrow
::Ref(r
, m
) => {
334 tcx
.lift(&r
).map(|r
| ty
::adjustment
::AutoBorrow
::Ref(r
, m
))
336 ty
::adjustment
::AutoBorrow
::RawPtr(m
) => {
337 Some(ty
::adjustment
::AutoBorrow
::RawPtr(m
))
343 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::GenSig
<'a
> {
344 type Lifted
= ty
::GenSig
<'tcx
>;
345 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
346 tcx
.lift(&(self.yield_ty
, self.return_ty
))
347 .map(|(yield_ty
, return_ty
)| {
356 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::FnSig
<'a
> {
357 type Lifted
= ty
::FnSig
<'tcx
>;
358 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
359 tcx
.lift(&self.inputs_and_output
).map(|x
| {
361 inputs_and_output
: x
,
362 variadic
: self.variadic
,
363 unsafety
: self.unsafety
,
370 impl<'tcx
, T
: Lift
<'tcx
>> Lift
<'tcx
> for ty
::error
::ExpectedFound
<T
> {
371 type Lifted
= ty
::error
::ExpectedFound
<T
::Lifted
>;
372 fn lift_to_tcx
<'a
, 'gcx
>(&self, tcx
: TyCtxt
<'a
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
373 tcx
.lift(&self.expected
).and_then(|expected
| {
374 tcx
.lift(&self.found
).map(|found
| {
375 ty
::error
::ExpectedFound
{
384 impl<'a
, 'tcx
> Lift
<'tcx
> for type_variable
::Default
<'a
> {
385 type Lifted
= type_variable
::Default
<'tcx
>;
386 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
387 tcx
.lift(&self.ty
).map(|ty
| {
388 type_variable
::Default
{
390 origin_span
: self.origin_span
,
397 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::error
::TypeError
<'a
> {
398 type Lifted
= ty
::error
::TypeError
<'tcx
>;
399 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
400 use ty
::error
::TypeError
::*;
403 Mismatch
=> Mismatch
,
404 UnsafetyMismatch(x
) => UnsafetyMismatch(x
),
405 AbiMismatch(x
) => AbiMismatch(x
),
406 Mutability
=> Mutability
,
407 TupleSize(x
) => TupleSize(x
),
408 FixedArraySize(x
) => FixedArraySize(x
),
409 ArgCount
=> ArgCount
,
410 RegionsDoesNotOutlive(a
, b
) => {
411 return tcx
.lift(&(a
, b
)).map(|(a
, b
)| RegionsDoesNotOutlive(a
, b
))
413 RegionsInsufficientlyPolymorphic(a
, b
) => {
414 return tcx
.lift(&b
).map(|b
| RegionsInsufficientlyPolymorphic(a
, b
))
416 RegionsOverlyPolymorphic(a
, b
) => {
417 return tcx
.lift(&b
).map(|b
| RegionsOverlyPolymorphic(a
, b
))
419 IntMismatch(x
) => IntMismatch(x
),
420 FloatMismatch(x
) => FloatMismatch(x
),
421 Traits(x
) => Traits(x
),
422 VariadicMismatch(x
) => VariadicMismatch(x
),
423 CyclicTy
=> CyclicTy
,
424 ProjectionMismatched(x
) => ProjectionMismatched(x
),
425 ProjectionBoundsLength(x
) => ProjectionBoundsLength(x
),
427 Sorts(ref x
) => return tcx
.lift(x
).map(Sorts
),
428 TyParamDefaultMismatch(ref x
) => {
429 return tcx
.lift(x
).map(TyParamDefaultMismatch
)
431 ExistentialMismatch(ref x
) => return tcx
.lift(x
).map(ExistentialMismatch
),
432 OldStyleLUB(ref x
) => return tcx
.lift(x
).map(OldStyleLUB
),
437 impl<'a
, 'tcx
> Lift
<'tcx
> for ConstEvalErr
<'a
> {
438 type Lifted
= ConstEvalErr
<'tcx
>;
439 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
440 tcx
.lift(&self.kind
).map(|kind
| {
449 impl<'a
, 'tcx
> Lift
<'tcx
> for const_val
::ErrKind
<'a
> {
450 type Lifted
= const_val
::ErrKind
<'tcx
>;
451 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
452 use middle
::const_val
::ErrKind
::*;
455 CannotCast
=> CannotCast
,
456 MissingStructField
=> MissingStructField
,
457 NonConstPath
=> NonConstPath
,
458 UnimplementedConstVal(s
) => UnimplementedConstVal(s
),
459 ExpectedConstTuple
=> ExpectedConstTuple
,
460 ExpectedConstStruct
=> ExpectedConstStruct
,
461 IndexedNonVec
=> IndexedNonVec
,
462 IndexNotUsize
=> IndexNotUsize
,
463 IndexOutOfBounds { len, index }
=> IndexOutOfBounds { len, index }
,
464 MiscBinaryOp
=> MiscBinaryOp
,
465 MiscCatchAll
=> MiscCatchAll
,
466 IndexOpFeatureGated
=> IndexOpFeatureGated
,
467 Math(ref e
) => Math(e
.clone()),
469 LayoutError(ref e
) => {
470 return tcx
.lift(e
).map(LayoutError
)
472 ErroneousReferencedConstant(ref e
) => {
473 return tcx
.lift(e
).map(ErroneousReferencedConstant
)
476 TypeckError
=> TypeckError
,
481 impl<'a
, 'tcx
> Lift
<'tcx
> for ty
::layout
::LayoutError
<'a
> {
482 type Lifted
= ty
::layout
::LayoutError
<'tcx
>;
483 fn lift_to_tcx
<'b
, 'gcx
>(&self, tcx
: TyCtxt
<'b
, 'gcx
, 'tcx
>) -> Option
<Self::Lifted
> {
485 ty
::layout
::LayoutError
::Unknown(ref ty
) => {
486 tcx
.lift(ty
).map(ty
::layout
::LayoutError
::Unknown
)
488 ty
::layout
::LayoutError
::SizeOverflow(ref ty
) => {
489 tcx
.lift(ty
).map(ty
::layout
::LayoutError
::SizeOverflow
)
495 ///////////////////////////////////////////////////////////////////////////
496 // TypeFoldable implementations.
498 // Ideally, each type should invoke `folder.fold_foo(self)` and
499 // nothing else. In some cases, though, we haven't gotten around to
500 // adding methods on the `folder` yet, and thus the folding is
501 // hard-coded here. This is less-flexible, because folders cannot
502 // override the behavior, but there are a lot of random types and one
503 // can easily refactor the folding into the TypeFolder trait as
506 macro_rules
! CopyImpls
{
509 impl<'tcx
> Lift
<'tcx
> for $ty
{
511 fn lift_to_tcx
<'a
, 'gcx
>(&self, _
: TyCtxt
<'a
, 'gcx
, 'tcx
>) -> Option
<Self> {
516 impl<'tcx
> TypeFoldable
<'tcx
> for $ty
{
517 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, _
: &mut F
) -> $ty
{
521 fn super_visit_with
<F
: TypeVisitor
<'tcx
>>(&self, _
: &mut F
) -> bool
{
529 CopyImpls
! { (), hir::Unsafety, abi::Abi, hir::def_id::DefId, ::mir::Local }
531 impl<'tcx
, T
:TypeFoldable
<'tcx
>, U
:TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for (T
, U
) {
532 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> (T
, U
) {
533 (self.0.fold_with
(folder
), self.1.fold_with
(folder
))
536 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
537 self.0.visit_with(visitor
) || self.1.visit_with(visitor
)
541 impl<'tcx
, T
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for Option
<T
> {
542 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
543 self.as_ref().map(|t
| t
.fold_with(folder
))
546 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
547 self.iter().any(|t
| t
.visit_with(visitor
))
551 impl<'tcx
, T
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for Rc
<T
> {
552 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
553 Rc
::new((**self).fold_with(folder
))
556 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
557 (**self).visit_with(visitor
)
561 impl<'tcx
, T
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for Box
<T
> {
562 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
563 let content
: T
= (**self).fold_with(folder
);
567 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
568 (**self).visit_with(visitor
)
572 impl<'tcx
, T
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for Vec
<T
> {
573 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
574 self.iter().map(|t
| t
.fold_with(folder
)).collect()
577 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
578 self.iter().any(|t
| t
.visit_with(visitor
))
582 impl<'tcx
, T
:TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for ty
::Binder
<T
> {
583 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
584 ty
::Binder(self.0.fold_with
(folder
))
587 fn fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
588 folder
.fold_binder(self)
591 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
592 self.0.visit_with(visitor
)
595 fn visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
596 visitor
.visit_binder(self)
600 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ParamEnv
<'tcx
> {
601 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
604 caller_bounds
: self.caller_bounds
.fold_with(folder
),
608 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
609 let &ty
::ParamEnv { reveal: _, ref caller_bounds }
= self;
610 caller_bounds
.super_visit_with(visitor
)
614 impl<'tcx
> TypeFoldable
<'tcx
> for &'tcx ty
::Slice
<ty
::ExistentialPredicate
<'tcx
>> {
615 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
616 let v
= self.iter().map(|p
| p
.fold_with(folder
)).collect
::<AccumulateVec
<[_
; 8]>>();
617 folder
.tcx().intern_existential_predicates(&v
)
620 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
621 self.iter().any(|p
| p
.visit_with(visitor
))
625 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ExistentialPredicate
<'tcx
> {
626 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
627 use ty
::ExistentialPredicate
::*;
629 Trait(ref tr
) => Trait(tr
.fold_with(folder
)),
630 Projection(ref p
) => Projection(p
.fold_with(folder
)),
631 AutoTrait(did
) => AutoTrait(did
),
635 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
637 ty
::ExistentialPredicate
::Trait(ref tr
) => tr
.visit_with(visitor
),
638 ty
::ExistentialPredicate
::Projection(ref p
) => p
.visit_with(visitor
),
639 ty
::ExistentialPredicate
::AutoTrait(_
) => false,
644 impl<'tcx
> TypeFoldable
<'tcx
> for &'tcx ty
::Slice
<Ty
<'tcx
>> {
645 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
646 let v
= self.iter().map(|t
| t
.fold_with(folder
)).collect
::<AccumulateVec
<[_
; 8]>>();
647 folder
.tcx().intern_type_list(&v
)
650 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
651 self.iter().any(|t
| t
.visit_with(visitor
))
655 impl<'tcx
> TypeFoldable
<'tcx
> for Ty
<'tcx
> {
656 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
657 let sty
= match self.sty
{
658 ty
::TyRawPtr(tm
) => ty
::TyRawPtr(tm
.fold_with(folder
)),
659 ty
::TyArray(typ
, sz
) => ty
::TyArray(typ
.fold_with(folder
), sz
.fold_with(folder
)),
660 ty
::TySlice(typ
) => ty
::TySlice(typ
.fold_with(folder
)),
661 ty
::TyAdt(tid
, substs
) => ty
::TyAdt(tid
, substs
.fold_with(folder
)),
662 ty
::TyDynamic(ref trait_ty
, ref region
) =>
663 ty
::TyDynamic(trait_ty
.fold_with(folder
), region
.fold_with(folder
)),
664 ty
::TyTuple(ts
, defaulted
) => ty
::TyTuple(ts
.fold_with(folder
), defaulted
),
665 ty
::TyFnDef(def_id
, substs
) => {
666 ty
::TyFnDef(def_id
, substs
.fold_with(folder
))
668 ty
::TyFnPtr(f
) => ty
::TyFnPtr(f
.fold_with(folder
)),
669 ty
::TyRef(ref r
, tm
) => {
670 ty
::TyRef(r
.fold_with(folder
), tm
.fold_with(folder
))
672 ty
::TyGenerator(did
, substs
, interior
) => {
673 ty
::TyGenerator(did
, substs
.fold_with(folder
), interior
.fold_with(folder
))
675 ty
::TyClosure(did
, substs
) => ty
::TyClosure(did
, substs
.fold_with(folder
)),
676 ty
::TyProjection(ref data
) => ty
::TyProjection(data
.fold_with(folder
)),
677 ty
::TyAnon(did
, substs
) => ty
::TyAnon(did
, substs
.fold_with(folder
)),
678 ty
::TyBool
| ty
::TyChar
| ty
::TyStr
| ty
::TyInt(_
) |
679 ty
::TyUint(_
) | ty
::TyFloat(_
) | ty
::TyError
| ty
::TyInfer(_
) |
680 ty
::TyParam(..) | ty
::TyNever
| ty
::TyForeign(..) => return self
686 folder
.tcx().mk_ty(sty
)
690 fn fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
691 folder
.fold_ty(*self)
694 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
696 ty
::TyRawPtr(ref tm
) => tm
.visit_with(visitor
),
697 ty
::TyArray(typ
, sz
) => typ
.visit_with(visitor
) || sz
.visit_with(visitor
),
698 ty
::TySlice(typ
) => typ
.visit_with(visitor
),
699 ty
::TyAdt(_
, substs
) => substs
.visit_with(visitor
),
700 ty
::TyDynamic(ref trait_ty
, ref reg
) =>
701 trait_ty
.visit_with(visitor
) || reg
.visit_with(visitor
),
702 ty
::TyTuple(ts
, _
) => ts
.visit_with(visitor
),
703 ty
::TyFnDef(_
, substs
) => substs
.visit_with(visitor
),
704 ty
::TyFnPtr(ref f
) => f
.visit_with(visitor
),
705 ty
::TyRef(r
, ref tm
) => r
.visit_with(visitor
) || tm
.visit_with(visitor
),
706 ty
::TyGenerator(_did
, ref substs
, ref interior
) => {
707 substs
.visit_with(visitor
) || interior
.visit_with(visitor
)
709 ty
::TyClosure(_did
, ref substs
) => substs
.visit_with(visitor
),
710 ty
::TyProjection(ref data
) => data
.visit_with(visitor
),
711 ty
::TyAnon(_
, ref substs
) => substs
.visit_with(visitor
),
712 ty
::TyBool
| ty
::TyChar
| ty
::TyStr
| ty
::TyInt(_
) |
713 ty
::TyUint(_
) | ty
::TyFloat(_
) | ty
::TyError
| ty
::TyInfer(_
) |
714 ty
::TyParam(..) | ty
::TyNever
| ty
::TyForeign(..) => false,
718 fn visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
719 visitor
.visit_ty(self)
723 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::TypeAndMut
<'tcx
> {
724 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
725 ty
::TypeAndMut { ty: self.ty.fold_with(folder), mutbl: self.mutbl }
728 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
729 self.ty
.visit_with(visitor
)
733 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::GenSig
<'tcx
> {
734 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
736 yield_ty
: self.yield_ty
.fold_with(folder
),
737 return_ty
: self.return_ty
.fold_with(folder
),
741 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
742 self.yield_ty
.visit_with(visitor
) ||
743 self.return_ty
.visit_with(visitor
)
747 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::FnSig
<'tcx
> {
748 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
749 let inputs_and_output
= self.inputs_and_output
.fold_with(folder
);
751 inputs_and_output
: folder
.tcx().intern_type_list(&inputs_and_output
),
752 variadic
: self.variadic
,
753 unsafety
: self.unsafety
,
758 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
759 self.inputs().iter().any(|i
| i
.visit_with(visitor
)) ||
760 self.output().visit_with(visitor
)
764 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::TraitRef
<'tcx
> {
765 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
768 substs
: self.substs
.fold_with(folder
),
772 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
773 self.substs
.visit_with(visitor
)
777 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ExistentialTraitRef
<'tcx
> {
778 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
779 ty
::ExistentialTraitRef
{
781 substs
: self.substs
.fold_with(folder
),
785 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
786 self.substs
.visit_with(visitor
)
790 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ImplHeader
<'tcx
> {
791 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
793 impl_def_id
: self.impl_def_id
,
794 self_ty
: self.self_ty
.fold_with(folder
),
795 trait_ref
: self.trait_ref
.map(|t
| t
.fold_with(folder
)),
796 predicates
: self.predicates
.iter().map(|p
| p
.fold_with(folder
)).collect(),
800 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
801 self.self_ty
.visit_with(visitor
) ||
802 self.trait_ref
.map(|r
| r
.visit_with(visitor
)).unwrap_or(false) ||
803 self.predicates
.iter().any(|p
| p
.visit_with(visitor
))
807 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::Region
<'tcx
> {
808 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, _folder
: &mut F
) -> Self {
812 fn fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
813 folder
.fold_region(*self)
816 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, _visitor
: &mut V
) -> bool
{
820 fn visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
821 visitor
.visit_region(*self)
825 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ClosureSubsts
<'tcx
> {
826 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
828 substs
: self.substs
.fold_with(folder
),
832 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
833 self.substs
.visit_with(visitor
)
837 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::GeneratorInterior
<'tcx
> {
838 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
839 ty
::GeneratorInterior
::new(self.witness
.fold_with(folder
))
842 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
843 self.witness
.visit_with(visitor
)
847 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::adjustment
::Adjustment
<'tcx
> {
848 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
849 ty
::adjustment
::Adjustment
{
850 kind
: self.kind
.fold_with(folder
),
851 target
: self.target
.fold_with(folder
),
855 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
856 self.kind
.visit_with(visitor
) ||
857 self.target
.visit_with(visitor
)
861 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::adjustment
::Adjust
<'tcx
> {
862 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
864 ty
::adjustment
::Adjust
::NeverToAny
|
865 ty
::adjustment
::Adjust
::ReifyFnPointer
|
866 ty
::adjustment
::Adjust
::UnsafeFnPointer
|
867 ty
::adjustment
::Adjust
::ClosureFnPointer
|
868 ty
::adjustment
::Adjust
::MutToConstPointer
|
869 ty
::adjustment
::Adjust
::Unsize
=> self.clone(),
870 ty
::adjustment
::Adjust
::Deref(ref overloaded
) => {
871 ty
::adjustment
::Adjust
::Deref(overloaded
.fold_with(folder
))
873 ty
::adjustment
::Adjust
::Borrow(ref autoref
) => {
874 ty
::adjustment
::Adjust
::Borrow(autoref
.fold_with(folder
))
879 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
881 ty
::adjustment
::Adjust
::NeverToAny
|
882 ty
::adjustment
::Adjust
::ReifyFnPointer
|
883 ty
::adjustment
::Adjust
::UnsafeFnPointer
|
884 ty
::adjustment
::Adjust
::ClosureFnPointer
|
885 ty
::adjustment
::Adjust
::MutToConstPointer
|
886 ty
::adjustment
::Adjust
::Unsize
=> false,
887 ty
::adjustment
::Adjust
::Deref(ref overloaded
) => {
888 overloaded
.visit_with(visitor
)
890 ty
::adjustment
::Adjust
::Borrow(ref autoref
) => {
891 autoref
.visit_with(visitor
)
897 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::adjustment
::OverloadedDeref
<'tcx
> {
898 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
899 ty
::adjustment
::OverloadedDeref
{
900 region
: self.region
.fold_with(folder
),
905 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
906 self.region
.visit_with(visitor
)
910 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::adjustment
::AutoBorrow
<'tcx
> {
911 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
913 ty
::adjustment
::AutoBorrow
::Ref(ref r
, m
) => {
914 ty
::adjustment
::AutoBorrow
::Ref(r
.fold_with(folder
), m
)
916 ty
::adjustment
::AutoBorrow
::RawPtr(m
) => ty
::adjustment
::AutoBorrow
::RawPtr(m
)
920 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
922 ty
::adjustment
::AutoBorrow
::Ref(r
, _m
) => r
.visit_with(visitor
),
923 ty
::adjustment
::AutoBorrow
::RawPtr(_m
) => false,
928 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::GenericPredicates
<'tcx
> {
929 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
930 ty
::GenericPredicates
{
932 predicates
: self.predicates
.fold_with(folder
),
936 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
937 self.predicates
.visit_with(visitor
)
941 impl<'tcx
> TypeFoldable
<'tcx
> for &'tcx ty
::Slice
<ty
::Predicate
<'tcx
>> {
942 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
943 let v
= self.iter().map(|p
| p
.fold_with(folder
)).collect
::<AccumulateVec
<[_
; 8]>>();
944 folder
.tcx().intern_predicates(&v
)
947 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
948 self.iter().any(|p
| p
.visit_with(visitor
))
952 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::Predicate
<'tcx
> {
953 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
955 ty
::Predicate
::Trait(ref a
) =>
956 ty
::Predicate
::Trait(a
.fold_with(folder
)),
957 ty
::Predicate
::Equate(ref binder
) =>
958 ty
::Predicate
::Equate(binder
.fold_with(folder
)),
959 ty
::Predicate
::Subtype(ref binder
) =>
960 ty
::Predicate
::Subtype(binder
.fold_with(folder
)),
961 ty
::Predicate
::RegionOutlives(ref binder
) =>
962 ty
::Predicate
::RegionOutlives(binder
.fold_with(folder
)),
963 ty
::Predicate
::TypeOutlives(ref binder
) =>
964 ty
::Predicate
::TypeOutlives(binder
.fold_with(folder
)),
965 ty
::Predicate
::Projection(ref binder
) =>
966 ty
::Predicate
::Projection(binder
.fold_with(folder
)),
967 ty
::Predicate
::WellFormed(data
) =>
968 ty
::Predicate
::WellFormed(data
.fold_with(folder
)),
969 ty
::Predicate
::ClosureKind(closure_def_id
, kind
) =>
970 ty
::Predicate
::ClosureKind(closure_def_id
, kind
),
971 ty
::Predicate
::ObjectSafe(trait_def_id
) =>
972 ty
::Predicate
::ObjectSafe(trait_def_id
),
973 ty
::Predicate
::ConstEvaluatable(def_id
, substs
) =>
974 ty
::Predicate
::ConstEvaluatable(def_id
, substs
.fold_with(folder
)),
978 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
980 ty
::Predicate
::Trait(ref a
) => a
.visit_with(visitor
),
981 ty
::Predicate
::Equate(ref binder
) => binder
.visit_with(visitor
),
982 ty
::Predicate
::Subtype(ref binder
) => binder
.visit_with(visitor
),
983 ty
::Predicate
::RegionOutlives(ref binder
) => binder
.visit_with(visitor
),
984 ty
::Predicate
::TypeOutlives(ref binder
) => binder
.visit_with(visitor
),
985 ty
::Predicate
::Projection(ref binder
) => binder
.visit_with(visitor
),
986 ty
::Predicate
::WellFormed(data
) => data
.visit_with(visitor
),
987 ty
::Predicate
::ClosureKind(_closure_def_id
, _kind
) => false,
988 ty
::Predicate
::ObjectSafe(_trait_def_id
) => false,
989 ty
::Predicate
::ConstEvaluatable(_def_id
, substs
) => substs
.visit_with(visitor
),
994 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ProjectionPredicate
<'tcx
> {
995 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
996 ty
::ProjectionPredicate
{
997 projection_ty
: self.projection_ty
.fold_with(folder
),
998 ty
: self.ty
.fold_with(folder
),
1002 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1003 self.projection_ty
.visit_with(visitor
) || self.ty
.visit_with(visitor
)
1007 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ExistentialProjection
<'tcx
> {
1008 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
1009 ty
::ExistentialProjection
{
1010 ty
: self.ty
.fold_with(folder
),
1011 substs
: self.substs
.fold_with(folder
),
1012 item_def_id
: self.item_def_id
,
1016 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1017 self.substs
.visit_with(visitor
) || self.ty
.visit_with(visitor
)
1021 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ProjectionTy
<'tcx
> {
1022 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
1024 substs
: self.substs
.fold_with(folder
),
1025 item_def_id
: self.item_def_id
,
1029 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1030 self.substs
.visit_with(visitor
)
1034 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::InstantiatedPredicates
<'tcx
> {
1035 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
1036 ty
::InstantiatedPredicates
{
1037 predicates
: self.predicates
.fold_with(folder
),
1041 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1042 self.predicates
.visit_with(visitor
)
1046 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::EquatePredicate
<'tcx
> {
1047 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
1048 ty
::EquatePredicate(self.0.fold_with
(folder
), self.1.fold_with
(folder
))
1051 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1052 self.0.visit_with(visitor
) || self.1.visit_with(visitor
)
1056 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::SubtypePredicate
<'tcx
> {
1057 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
1058 ty
::SubtypePredicate
{
1059 a_is_expected
: self.a_is_expected
,
1060 a
: self.a
.fold_with(folder
),
1061 b
: self.b
.fold_with(folder
)
1065 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1066 self.a
.visit_with(visitor
) || self.b
.visit_with(visitor
)
1070 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::TraitPredicate
<'tcx
> {
1071 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
1072 ty
::TraitPredicate
{
1073 trait_ref
: self.trait_ref
.fold_with(folder
)
1077 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1078 self.trait_ref
.visit_with(visitor
)
1082 impl<'tcx
,T
,U
> TypeFoldable
<'tcx
> for ty
::OutlivesPredicate
<T
,U
>
1083 where T
: TypeFoldable
<'tcx
>,
1084 U
: TypeFoldable
<'tcx
>,
1086 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
1087 ty
::OutlivesPredicate(self.0.fold_with
(folder
),
1088 self.1.fold_with
(folder
))
1091 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1092 self.0.visit_with(visitor
) || self.1.visit_with(visitor
)
1096 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::ClosureUpvar
<'tcx
> {
1097 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
1101 ty
: self.ty
.fold_with(folder
),
1105 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1106 self.ty
.visit_with(visitor
)
1110 impl<'tcx
, T
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for ty
::error
::ExpectedFound
<T
> {
1111 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
1112 ty
::error
::ExpectedFound
{
1113 expected
: self.expected
.fold_with(folder
),
1114 found
: self.found
.fold_with(folder
),
1118 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1119 self.expected
.visit_with(visitor
) || self.found
.visit_with(visitor
)
1123 impl<'tcx
> TypeFoldable
<'tcx
> for type_variable
::Default
<'tcx
> {
1124 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
1125 type_variable
::Default
{
1126 ty
: self.ty
.fold_with(folder
),
1127 origin_span
: self.origin_span
,
1132 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1133 self.ty
.visit_with(visitor
)
1137 impl<'tcx
, T
: TypeFoldable
<'tcx
>, I
: Idx
> TypeFoldable
<'tcx
> for IndexVec
<I
, T
> {
1138 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
1139 self.iter().map(|x
| x
.fold_with(folder
)).collect()
1142 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1143 self.iter().any(|t
| t
.visit_with(visitor
))
1147 impl<'tcx
> TypeFoldable
<'tcx
> for ty
::error
::TypeError
<'tcx
> {
1148 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
1149 use ty
::error
::TypeError
::*;
1152 Mismatch
=> Mismatch
,
1153 UnsafetyMismatch(x
) => UnsafetyMismatch(x
.fold_with(folder
)),
1154 AbiMismatch(x
) => AbiMismatch(x
.fold_with(folder
)),
1155 Mutability
=> Mutability
,
1156 TupleSize(x
) => TupleSize(x
),
1157 FixedArraySize(x
) => FixedArraySize(x
),
1158 ArgCount
=> ArgCount
,
1159 RegionsDoesNotOutlive(a
, b
) => {
1160 RegionsDoesNotOutlive(a
.fold_with(folder
), b
.fold_with(folder
))
1162 RegionsInsufficientlyPolymorphic(a
, b
) => {
1163 RegionsInsufficientlyPolymorphic(a
, b
.fold_with(folder
))
1165 RegionsOverlyPolymorphic(a
, b
) => {
1166 RegionsOverlyPolymorphic(a
, b
.fold_with(folder
))
1168 IntMismatch(x
) => IntMismatch(x
),
1169 FloatMismatch(x
) => FloatMismatch(x
),
1170 Traits(x
) => Traits(x
),
1171 VariadicMismatch(x
) => VariadicMismatch(x
),
1172 CyclicTy
=> CyclicTy
,
1173 ProjectionMismatched(x
) => ProjectionMismatched(x
),
1174 ProjectionBoundsLength(x
) => ProjectionBoundsLength(x
),
1175 Sorts(x
) => Sorts(x
.fold_with(folder
)),
1176 TyParamDefaultMismatch(ref x
) => TyParamDefaultMismatch(x
.fold_with(folder
)),
1177 ExistentialMismatch(x
) => ExistentialMismatch(x
.fold_with(folder
)),
1178 OldStyleLUB(ref x
) => OldStyleLUB(x
.fold_with(folder
)),
1182 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1183 use ty
::error
::TypeError
::*;
1186 UnsafetyMismatch(x
) => x
.visit_with(visitor
),
1187 AbiMismatch(x
) => x
.visit_with(visitor
),
1188 RegionsDoesNotOutlive(a
, b
) => {
1189 a
.visit_with(visitor
) || b
.visit_with(visitor
)
1191 RegionsInsufficientlyPolymorphic(_
, b
) |
1192 RegionsOverlyPolymorphic(_
, b
) => {
1193 b
.visit_with(visitor
)
1195 Sorts(x
) => x
.visit_with(visitor
),
1196 OldStyleLUB(ref x
) => x
.visit_with(visitor
),
1197 TyParamDefaultMismatch(ref x
) => x
.visit_with(visitor
),
1198 ExistentialMismatch(x
) => x
.visit_with(visitor
),
1207 VariadicMismatch(_
) |
1209 ProjectionMismatched(_
) |
1210 ProjectionBoundsLength(_
) => false,
1215 impl<'tcx
> TypeFoldable
<'tcx
> for ConstVal
<'tcx
> {
1216 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
1218 ConstVal
::Integral(i
) => ConstVal
::Integral(i
),
1219 ConstVal
::Float(f
) => ConstVal
::Float(f
),
1220 ConstVal
::Str(s
) => ConstVal
::Str(s
),
1221 ConstVal
::ByteStr(b
) => ConstVal
::ByteStr(b
),
1222 ConstVal
::Bool(b
) => ConstVal
::Bool(b
),
1223 ConstVal
::Char(c
) => ConstVal
::Char(c
),
1224 ConstVal
::Variant(def_id
) => ConstVal
::Variant(def_id
),
1225 ConstVal
::Function(def_id
, substs
) => {
1226 ConstVal
::Function(def_id
, substs
.fold_with(folder
))
1228 ConstVal
::Aggregate(ConstAggregate
::Struct(fields
)) => {
1229 let new_fields
: Vec
<_
> = fields
.iter().map(|&(name
, v
)| {
1230 (name
, v
.fold_with(folder
))
1232 let fields
= if new_fields
== fields
{
1235 folder
.tcx().alloc_name_const_slice(&new_fields
)
1237 ConstVal
::Aggregate(ConstAggregate
::Struct(fields
))
1239 ConstVal
::Aggregate(ConstAggregate
::Tuple(fields
)) => {
1240 let new_fields
: Vec
<_
> = fields
.iter().map(|v
| {
1243 let fields
= if new_fields
== fields
{
1246 folder
.tcx().alloc_const_slice(&new_fields
)
1248 ConstVal
::Aggregate(ConstAggregate
::Tuple(fields
))
1250 ConstVal
::Aggregate(ConstAggregate
::Array(fields
)) => {
1251 let new_fields
: Vec
<_
> = fields
.iter().map(|v
| {
1254 let fields
= if new_fields
== fields
{
1257 folder
.tcx().alloc_const_slice(&new_fields
)
1259 ConstVal
::Aggregate(ConstAggregate
::Array(fields
))
1261 ConstVal
::Aggregate(ConstAggregate
::Repeat(v
, count
)) => {
1262 let v
= v
.fold_with(folder
);
1263 ConstVal
::Aggregate(ConstAggregate
::Repeat(v
, count
))
1265 ConstVal
::Unevaluated(def_id
, substs
) => {
1266 ConstVal
::Unevaluated(def_id
, substs
.fold_with(folder
))
1271 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1273 ConstVal
::Integral(_
) |
1274 ConstVal
::Float(_
) |
1276 ConstVal
::ByteStr(_
) |
1279 ConstVal
::Variant(_
) => false,
1280 ConstVal
::Function(_
, substs
) => substs
.visit_with(visitor
),
1281 ConstVal
::Aggregate(ConstAggregate
::Struct(fields
)) => {
1282 fields
.iter().any(|&(_
, v
)| v
.visit_with(visitor
))
1284 ConstVal
::Aggregate(ConstAggregate
::Tuple(fields
)) |
1285 ConstVal
::Aggregate(ConstAggregate
::Array(fields
)) => {
1286 fields
.iter().any(|v
| v
.visit_with(visitor
))
1288 ConstVal
::Aggregate(ConstAggregate
::Repeat(v
, _
)) => {
1289 v
.visit_with(visitor
)
1291 ConstVal
::Unevaluated(_
, substs
) => substs
.visit_with(visitor
),
1296 impl<'tcx
> TypeFoldable
<'tcx
> for &'tcx ty
::Const
<'tcx
> {
1297 fn super_fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
1298 let ty
= self.ty
.fold_with(folder
);
1299 let val
= self.val
.fold_with(folder
);
1300 folder
.tcx().mk_const(ty
::Const
{
1306 fn fold_with
<'gcx
: 'tcx
, F
: TypeFolder
<'gcx
, 'tcx
>>(&self, folder
: &mut F
) -> Self {
1307 folder
.fold_const(*self)
1310 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1311 self.ty
.visit_with(visitor
) || self.val
.visit_with(visitor
)
1314 fn visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
1315 visitor
.visit_const(self)