]>
Commit | Line | Data |
---|---|---|
e9174d1e SL |
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. | |
4 | // | |
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. | |
10 | ||
a7813a04 | 11 | use infer::type_variable; |
9e0c209e | 12 | use ty::{self, Lift, Ty, TyCtxt}; |
54a0048b | 13 | use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; |
c30ab7b3 | 14 | use rustc_data_structures::accumulate_vec::AccumulateVec; |
8bb4bdeb | 15 | use rustc_data_structures::indexed_vec::{IndexVec, Idx}; |
e9174d1e SL |
16 | |
17 | use std::rc::Rc; | |
18 | use syntax::abi; | |
e9174d1e | 19 | |
54a0048b | 20 | use hir; |
e9174d1e | 21 | |
e9174d1e SL |
22 | /////////////////////////////////////////////////////////////////////////// |
23 | // Lift implementations | |
24 | ||
25 | impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>> Lift<'tcx> for (A, B) { | |
26 | type Lifted = (A::Lifted, B::Lifted); | |
a7813a04 | 27 | fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> { |
e9174d1e SL |
28 | tcx.lift(&self.0).and_then(|a| tcx.lift(&self.1).map(|b| (a, b))) |
29 | } | |
30 | } | |
31 | ||
a7813a04 XL |
32 | impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> { |
33 | type Lifted = Option<T::Lifted>; | |
34 | fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> { | |
35 | match *self { | |
36 | Some(ref x) => tcx.lift(x).map(Some), | |
37 | None => Some(None) | |
38 | } | |
39 | } | |
40 | } | |
41 | ||
42 | impl<'tcx, T: Lift<'tcx>, E: Lift<'tcx>> Lift<'tcx> for Result<T, E> { | |
43 | type Lifted = Result<T::Lifted, E::Lifted>; | |
44 | fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> { | |
45 | match *self { | |
46 | Ok(ref x) => tcx.lift(x).map(Ok), | |
47 | Err(ref e) => tcx.lift(e).map(Err) | |
48 | } | |
49 | } | |
50 | } | |
51 | ||
e9174d1e SL |
52 | impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for [T] { |
53 | type Lifted = Vec<T::Lifted>; | |
a7813a04 | 54 | fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> { |
b039eaaf SL |
55 | // type annotation needed to inform `projection_must_outlive` |
56 | let mut result : Vec<<T as Lift<'tcx>>::Lifted> | |
57 | = Vec::with_capacity(self.len()); | |
e9174d1e SL |
58 | for x in self { |
59 | if let Some(value) = tcx.lift(x) { | |
60 | result.push(value); | |
61 | } else { | |
62 | return None; | |
63 | } | |
64 | } | |
65 | Some(result) | |
66 | } | |
67 | } | |
68 | ||
a7813a04 XL |
69 | impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Vec<T> { |
70 | type Lifted = Vec<T::Lifted>; | |
71 | fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> { | |
72 | tcx.lift(&self[..]) | |
73 | } | |
74 | } | |
75 | ||
9e0c209e SL |
76 | impl<'a, 'tcx> Lift<'tcx> for ty::TraitRef<'a> { |
77 | type Lifted = ty::TraitRef<'tcx>; | |
78 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { | |
79 | tcx.lift(&self.substs).map(|substs| ty::TraitRef { | |
80 | def_id: self.def_id, | |
81 | substs: substs | |
82 | }) | |
e9174d1e SL |
83 | } |
84 | } | |
85 | ||
9e0c209e SL |
86 | impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialTraitRef<'a> { |
87 | type Lifted = ty::ExistentialTraitRef<'tcx>; | |
88 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { | |
89 | tcx.lift(&self.substs).map(|substs| ty::ExistentialTraitRef { | |
e9174d1e SL |
90 | def_id: self.def_id, |
91 | substs: substs | |
92 | }) | |
93 | } | |
94 | } | |
95 | ||
96 | impl<'a, 'tcx> Lift<'tcx> for ty::TraitPredicate<'a> { | |
97 | type Lifted = ty::TraitPredicate<'tcx>; | |
a7813a04 XL |
98 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) |
99 | -> Option<ty::TraitPredicate<'tcx>> { | |
e9174d1e SL |
100 | tcx.lift(&self.trait_ref).map(|trait_ref| ty::TraitPredicate { |
101 | trait_ref: trait_ref | |
102 | }) | |
103 | } | |
104 | } | |
105 | ||
106 | impl<'a, 'tcx> Lift<'tcx> for ty::EquatePredicate<'a> { | |
107 | type Lifted = ty::EquatePredicate<'tcx>; | |
a7813a04 XL |
108 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) |
109 | -> Option<ty::EquatePredicate<'tcx>> { | |
e9174d1e SL |
110 | tcx.lift(&(self.0, self.1)).map(|(a, b)| ty::EquatePredicate(a, b)) |
111 | } | |
112 | } | |
113 | ||
cc61c64b XL |
114 | impl<'a, 'tcx> Lift<'tcx> for ty::SubtypePredicate<'a> { |
115 | type Lifted = ty::SubtypePredicate<'tcx>; | |
116 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) | |
117 | -> Option<ty::SubtypePredicate<'tcx>> { | |
118 | tcx.lift(&(self.a, self.b)).map(|(a, b)| ty::SubtypePredicate { | |
119 | a_is_expected: self.a_is_expected, | |
120 | a: a, | |
121 | b: b, | |
122 | }) | |
123 | } | |
124 | } | |
125 | ||
e9174d1e SL |
126 | impl<'tcx, A: Copy+Lift<'tcx>, B: Copy+Lift<'tcx>> Lift<'tcx> for ty::OutlivesPredicate<A, B> { |
127 | type Lifted = ty::OutlivesPredicate<A::Lifted, B::Lifted>; | |
a7813a04 | 128 | fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> { |
e9174d1e SL |
129 | tcx.lift(&(self.0, self.1)).map(|(a, b)| ty::OutlivesPredicate(a, b)) |
130 | } | |
131 | } | |
132 | ||
5bcae85e SL |
133 | impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionTy<'a> { |
134 | type Lifted = ty::ProjectionTy<'tcx>; | |
135 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) | |
136 | -> Option<ty::ProjectionTy<'tcx>> { | |
137 | tcx.lift(&self.trait_ref).map(|trait_ref| { | |
7cac9316 | 138 | ty::ProjectionTy::from_ref_and_name(tcx, trait_ref, self.item_name(tcx)) |
5bcae85e SL |
139 | }) |
140 | } | |
141 | } | |
142 | ||
e9174d1e SL |
143 | impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionPredicate<'a> { |
144 | type Lifted = ty::ProjectionPredicate<'tcx>; | |
a7813a04 XL |
145 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) |
146 | -> Option<ty::ProjectionPredicate<'tcx>> { | |
5bcae85e | 147 | tcx.lift(&(self.projection_ty, self.ty)).map(|(projection_ty, ty)| { |
e9174d1e | 148 | ty::ProjectionPredicate { |
5bcae85e | 149 | projection_ty: projection_ty, |
e9174d1e SL |
150 | ty: ty |
151 | } | |
152 | }) | |
153 | } | |
154 | } | |
155 | ||
9e0c209e SL |
156 | impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> { |
157 | type Lifted = ty::ExistentialProjection<'tcx>; | |
158 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { | |
159 | tcx.lift(&(self.trait_ref, self.ty)).map(|(trait_ref, ty)| { | |
160 | ty::ExistentialProjection { | |
161 | trait_ref: trait_ref, | |
162 | item_name: self.item_name, | |
163 | ty: ty | |
164 | } | |
165 | }) | |
166 | } | |
167 | } | |
168 | ||
a7813a04 XL |
169 | impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> { |
170 | type Lifted = ty::Predicate<'tcx>; | |
171 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { | |
172 | match *self { | |
173 | ty::Predicate::Trait(ref binder) => { | |
174 | tcx.lift(binder).map(ty::Predicate::Trait) | |
175 | } | |
176 | ty::Predicate::Equate(ref binder) => { | |
177 | tcx.lift(binder).map(ty::Predicate::Equate) | |
178 | } | |
cc61c64b XL |
179 | ty::Predicate::Subtype(ref binder) => { |
180 | tcx.lift(binder).map(ty::Predicate::Subtype) | |
181 | } | |
a7813a04 XL |
182 | ty::Predicate::RegionOutlives(ref binder) => { |
183 | tcx.lift(binder).map(ty::Predicate::RegionOutlives) | |
184 | } | |
185 | ty::Predicate::TypeOutlives(ref binder) => { | |
186 | tcx.lift(binder).map(ty::Predicate::TypeOutlives) | |
187 | } | |
188 | ty::Predicate::Projection(ref binder) => { | |
189 | tcx.lift(binder).map(ty::Predicate::Projection) | |
190 | } | |
191 | ty::Predicate::WellFormed(ty) => { | |
192 | tcx.lift(&ty).map(ty::Predicate::WellFormed) | |
193 | } | |
a7813a04 XL |
194 | ty::Predicate::ClosureKind(closure_def_id, kind) => { |
195 | Some(ty::Predicate::ClosureKind(closure_def_id, kind)) | |
196 | } | |
197 | ty::Predicate::ObjectSafe(trait_def_id) => { | |
198 | Some(ty::Predicate::ObjectSafe(trait_def_id)) | |
199 | } | |
200 | } | |
201 | } | |
202 | } | |
203 | ||
e9174d1e SL |
204 | impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<T> { |
205 | type Lifted = ty::Binder<T::Lifted>; | |
a7813a04 | 206 | fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> { |
e9174d1e SL |
207 | tcx.lift(&self.0).map(|x| ty::Binder(x)) |
208 | } | |
209 | } | |
210 | ||
a7813a04 XL |
211 | impl<'a, 'tcx> Lift<'tcx> for ty::ClosureSubsts<'a> { |
212 | type Lifted = ty::ClosureSubsts<'tcx>; | |
213 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { | |
476ff2be SL |
214 | tcx.lift(&self.substs).map(|substs| { |
215 | ty::ClosureSubsts { substs: substs } | |
a7813a04 XL |
216 | }) |
217 | } | |
218 | } | |
219 | ||
7cac9316 XL |
220 | impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjustment<'a> { |
221 | type Lifted = ty::adjustment::Adjustment<'tcx>; | |
a7813a04 | 222 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { |
7cac9316 XL |
223 | tcx.lift(&self.kind).and_then(|kind| { |
224 | tcx.lift(&self.target).map(|target| { | |
225 | ty::adjustment::Adjustment { kind, target } | |
226 | }) | |
227 | }) | |
228 | } | |
229 | } | |
230 | ||
231 | impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> { | |
232 | type Lifted = ty::adjustment::Adjust<'tcx>; | |
233 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { | |
234 | match *self { | |
235 | ty::adjustment::Adjust::NeverToAny => | |
236 | Some(ty::adjustment::Adjust::NeverToAny), | |
237 | ty::adjustment::Adjust::ReifyFnPointer => | |
238 | Some(ty::adjustment::Adjust::ReifyFnPointer), | |
239 | ty::adjustment::Adjust::UnsafeFnPointer => | |
240 | Some(ty::adjustment::Adjust::UnsafeFnPointer), | |
241 | ty::adjustment::Adjust::ClosureFnPointer => | |
242 | Some(ty::adjustment::Adjust::ClosureFnPointer), | |
243 | ty::adjustment::Adjust::MutToConstPointer => | |
244 | Some(ty::adjustment::Adjust::MutToConstPointer), | |
245 | ty::adjustment::Adjust::Unsize => | |
246 | Some(ty::adjustment::Adjust::Unsize), | |
247 | ty::adjustment::Adjust::Deref(ref overloaded) => { | |
248 | tcx.lift(overloaded).map(ty::adjustment::Adjust::Deref) | |
249 | } | |
250 | ty::adjustment::Adjust::Borrow(ref autoref) => { | |
251 | tcx.lift(autoref).map(ty::adjustment::Adjust::Borrow) | |
252 | } | |
253 | } | |
254 | } | |
255 | } | |
256 | ||
257 | impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::OverloadedDeref<'a> { | |
258 | type Lifted = ty::adjustment::OverloadedDeref<'tcx>; | |
259 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { | |
260 | tcx.lift(&self.region).map(|region| { | |
261 | ty::adjustment::OverloadedDeref { | |
262 | region, | |
263 | mutbl: self.mutbl, | |
a7813a04 XL |
264 | } |
265 | }) | |
266 | } | |
267 | } | |
268 | ||
c30ab7b3 SL |
269 | impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::AutoBorrow<'a> { |
270 | type Lifted = ty::adjustment::AutoBorrow<'tcx>; | |
a7813a04 XL |
271 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { |
272 | match *self { | |
c30ab7b3 SL |
273 | ty::adjustment::AutoBorrow::Ref(r, m) => { |
274 | tcx.lift(&r).map(|r| ty::adjustment::AutoBorrow::Ref(r, m)) | |
a7813a04 | 275 | } |
c30ab7b3 SL |
276 | ty::adjustment::AutoBorrow::RawPtr(m) => { |
277 | Some(ty::adjustment::AutoBorrow::RawPtr(m)) | |
a7813a04 XL |
278 | } |
279 | } | |
280 | } | |
281 | } | |
282 | ||
a7813a04 XL |
283 | impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> { |
284 | type Lifted = ty::FnSig<'tcx>; | |
285 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { | |
476ff2be SL |
286 | tcx.lift(&self.inputs_and_output).map(|x| { |
287 | ty::FnSig { | |
288 | inputs_and_output: x, | |
8bb4bdeb | 289 | variadic: self.variadic, |
a7813a04 | 290 | unsafety: self.unsafety, |
8bb4bdeb | 291 | abi: self.abi, |
a7813a04 XL |
292 | } |
293 | }) | |
294 | } | |
295 | } | |
296 | ||
297 | impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::error::ExpectedFound<T> { | |
298 | type Lifted = ty::error::ExpectedFound<T::Lifted>; | |
299 | fn lift_to_tcx<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Self::Lifted> { | |
300 | tcx.lift(&self.expected).and_then(|expected| { | |
301 | tcx.lift(&self.found).map(|found| { | |
302 | ty::error::ExpectedFound { | |
303 | expected: expected, | |
304 | found: found | |
305 | } | |
306 | }) | |
307 | }) | |
308 | } | |
309 | } | |
310 | ||
311 | impl<'a, 'tcx> Lift<'tcx> for type_variable::Default<'a> { | |
312 | type Lifted = type_variable::Default<'tcx>; | |
313 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { | |
314 | tcx.lift(&self.ty).map(|ty| { | |
315 | type_variable::Default { | |
316 | ty: ty, | |
317 | origin_span: self.origin_span, | |
318 | def_id: self.def_id | |
319 | } | |
320 | }) | |
321 | } | |
322 | } | |
323 | ||
324 | impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> { | |
325 | type Lifted = ty::error::TypeError<'tcx>; | |
326 | fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> { | |
327 | use ty::error::TypeError::*; | |
328 | ||
329 | Some(match *self { | |
330 | Mismatch => Mismatch, | |
331 | UnsafetyMismatch(x) => UnsafetyMismatch(x), | |
332 | AbiMismatch(x) => AbiMismatch(x), | |
333 | Mutability => Mutability, | |
a7813a04 XL |
334 | TupleSize(x) => TupleSize(x), |
335 | FixedArraySize(x) => FixedArraySize(x), | |
a7813a04 | 336 | ArgCount => ArgCount, |
9e0c209e SL |
337 | RegionsDoesNotOutlive(a, b) => { |
338 | return tcx.lift(&(a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b)) | |
339 | } | |
340 | RegionsNotSame(a, b) => { | |
341 | return tcx.lift(&(a, b)).map(|(a, b)| RegionsNotSame(a, b)) | |
342 | } | |
343 | RegionsNoOverlap(a, b) => { | |
344 | return tcx.lift(&(a, b)).map(|(a, b)| RegionsNoOverlap(a, b)) | |
345 | } | |
8bb4bdeb XL |
346 | RegionsInsufficientlyPolymorphic(a, b, ref c) => { |
347 | let c = c.clone(); | |
348 | return tcx.lift(&b).map(|b| RegionsInsufficientlyPolymorphic(a, b, c)) | |
9e0c209e | 349 | } |
8bb4bdeb XL |
350 | RegionsOverlyPolymorphic(a, b, ref c) => { |
351 | let c = c.clone(); | |
352 | return tcx.lift(&b).map(|b| RegionsOverlyPolymorphic(a, b, c)) | |
a7813a04 | 353 | } |
a7813a04 XL |
354 | IntMismatch(x) => IntMismatch(x), |
355 | FloatMismatch(x) => FloatMismatch(x), | |
356 | Traits(x) => Traits(x), | |
a7813a04 XL |
357 | VariadicMismatch(x) => VariadicMismatch(x), |
358 | CyclicTy => CyclicTy, | |
a7813a04 XL |
359 | ProjectionNameMismatched(x) => ProjectionNameMismatched(x), |
360 | ProjectionBoundsLength(x) => ProjectionBoundsLength(x), | |
361 | ||
362 | Sorts(ref x) => return tcx.lift(x).map(Sorts), | |
363 | TyParamDefaultMismatch(ref x) => { | |
364 | return tcx.lift(x).map(TyParamDefaultMismatch) | |
365 | } | |
476ff2be | 366 | ExistentialMismatch(ref x) => return tcx.lift(x).map(ExistentialMismatch) |
a7813a04 XL |
367 | }) |
368 | } | |
369 | } | |
370 | ||
e9174d1e SL |
371 | /////////////////////////////////////////////////////////////////////////// |
372 | // TypeFoldable implementations. | |
373 | // | |
374 | // Ideally, each type should invoke `folder.fold_foo(self)` and | |
375 | // nothing else. In some cases, though, we haven't gotten around to | |
376 | // adding methods on the `folder` yet, and thus the folding is | |
377 | // hard-coded here. This is less-flexible, because folders cannot | |
378 | // override the behavior, but there are a lot of random types and one | |
379 | // can easily refactor the folding into the TypeFolder trait as | |
380 | // needed. | |
381 | ||
382 | macro_rules! CopyImpls { | |
383 | ($($ty:ty),+) => { | |
384 | $( | |
385 | impl<'tcx> TypeFoldable<'tcx> for $ty { | |
a7813a04 | 386 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _: &mut F) -> $ty { |
e9174d1e SL |
387 | *self |
388 | } | |
9cc50fc6 SL |
389 | |
390 | fn super_visit_with<F: TypeVisitor<'tcx>>(&self, _: &mut F) -> bool { | |
391 | false | |
392 | } | |
e9174d1e SL |
393 | } |
394 | )+ | |
395 | } | |
396 | } | |
397 | ||
8bb4bdeb | 398 | CopyImpls! { (), hir::Unsafety, abi::Abi } |
e9174d1e SL |
399 | |
400 | impl<'tcx, T:TypeFoldable<'tcx>, U:TypeFoldable<'tcx>> TypeFoldable<'tcx> for (T, U) { | |
a7813a04 | 401 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> (T, U) { |
e9174d1e SL |
402 | (self.0.fold_with(folder), self.1.fold_with(folder)) |
403 | } | |
9cc50fc6 SL |
404 | |
405 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
406 | self.0.visit_with(visitor) || self.1.visit_with(visitor) | |
407 | } | |
e9174d1e SL |
408 | } |
409 | ||
410 | impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Option<T> { | |
a7813a04 | 411 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
e9174d1e SL |
412 | self.as_ref().map(|t| t.fold_with(folder)) |
413 | } | |
9cc50fc6 SL |
414 | |
415 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
416 | self.iter().any(|t| t.visit_with(visitor)) | |
417 | } | |
e9174d1e SL |
418 | } |
419 | ||
420 | impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> { | |
a7813a04 | 421 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
e9174d1e SL |
422 | Rc::new((**self).fold_with(folder)) |
423 | } | |
9cc50fc6 SL |
424 | |
425 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
426 | (**self).visit_with(visitor) | |
427 | } | |
e9174d1e SL |
428 | } |
429 | ||
430 | impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> { | |
a7813a04 | 431 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
e9174d1e SL |
432 | let content: T = (**self).fold_with(folder); |
433 | box content | |
434 | } | |
9cc50fc6 SL |
435 | |
436 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
437 | (**self).visit_with(visitor) | |
438 | } | |
e9174d1e SL |
439 | } |
440 | ||
441 | impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> { | |
a7813a04 | 442 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
e9174d1e SL |
443 | self.iter().map(|t| t.fold_with(folder)).collect() |
444 | } | |
9cc50fc6 SL |
445 | |
446 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
447 | self.iter().any(|t| t.visit_with(visitor)) | |
448 | } | |
e9174d1e SL |
449 | } |
450 | ||
451 | impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> { | |
a7813a04 | 452 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
54a0048b | 453 | ty::Binder(self.0.fold_with(folder)) |
9cc50fc6 SL |
454 | } |
455 | ||
a7813a04 | 456 | fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
e9174d1e SL |
457 | folder.fold_binder(self) |
458 | } | |
9cc50fc6 SL |
459 | |
460 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
54a0048b SL |
461 | self.0.visit_with(visitor) |
462 | } | |
463 | ||
464 | fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
465 | visitor.visit_binder(self) | |
9cc50fc6 | 466 | } |
e9174d1e SL |
467 | } |
468 | ||
7cac9316 XL |
469 | impl<'tcx> TypeFoldable<'tcx> for ty::ParamEnv<'tcx> { |
470 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { | |
471 | ty::ParamEnv { | |
472 | reveal: self.reveal, | |
473 | caller_bounds: self.caller_bounds.fold_with(folder), | |
474 | } | |
475 | } | |
476 | ||
477 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
478 | let &ty::ParamEnv { reveal: _, ref caller_bounds } = self; | |
479 | caller_bounds.super_visit_with(visitor) | |
480 | } | |
481 | } | |
482 | ||
476ff2be | 483 | impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Slice<ty::ExistentialPredicate<'tcx>> { |
a7813a04 | 484 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
476ff2be SL |
485 | let v = self.iter().map(|p| p.fold_with(folder)).collect::<AccumulateVec<[_; 8]>>(); |
486 | folder.tcx().intern_existential_predicates(&v) | |
487 | } | |
488 | ||
489 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
490 | self.iter().any(|p| p.visit_with(visitor)) | |
491 | } | |
492 | } | |
493 | ||
494 | impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialPredicate<'tcx> { | |
495 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { | |
496 | use ty::ExistentialPredicate::*; | |
497 | match *self { | |
498 | Trait(ref tr) => Trait(tr.fold_with(folder)), | |
499 | Projection(ref p) => Projection(p.fold_with(folder)), | |
500 | AutoTrait(did) => AutoTrait(did), | |
9cc50fc6 SL |
501 | } |
502 | } | |
503 | ||
504 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
476ff2be SL |
505 | match *self { |
506 | ty::ExistentialPredicate::Trait(ref tr) => tr.visit_with(visitor), | |
507 | ty::ExistentialPredicate::Projection(ref p) => p.visit_with(visitor), | |
508 | ty::ExistentialPredicate::AutoTrait(_) => false, | |
509 | } | |
9cc50fc6 | 510 | } |
e9174d1e SL |
511 | } |
512 | ||
9e0c209e | 513 | impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Slice<Ty<'tcx>> { |
a7813a04 | 514 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
c30ab7b3 SL |
515 | let v = self.iter().map(|t| t.fold_with(folder)).collect::<AccumulateVec<[_; 8]>>(); |
516 | folder.tcx().intern_type_list(&v) | |
a7813a04 XL |
517 | } |
518 | ||
519 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
520 | self.iter().any(|t| t.visit_with(visitor)) | |
521 | } | |
522 | } | |
523 | ||
e9174d1e | 524 | impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> { |
a7813a04 | 525 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
9cc50fc6 | 526 | let sty = match self.sty { |
a7813a04 | 527 | ty::TyRawPtr(tm) => ty::TyRawPtr(tm.fold_with(folder)), |
9cc50fc6 SL |
528 | ty::TyArray(typ, sz) => ty::TyArray(typ.fold_with(folder), sz), |
529 | ty::TySlice(typ) => ty::TySlice(typ.fold_with(folder)), | |
9e0c209e | 530 | ty::TyAdt(tid, substs) => ty::TyAdt(tid, substs.fold_with(folder)), |
476ff2be SL |
531 | ty::TyDynamic(ref trait_ty, ref region) => |
532 | ty::TyDynamic(trait_ty.fold_with(folder), region.fold_with(folder)), | |
8bb4bdeb | 533 | ty::TyTuple(ts, defaulted) => ty::TyTuple(ts.fold_with(folder), defaulted), |
a7813a04 | 534 | ty::TyFnDef(def_id, substs, f) => { |
54a0048b | 535 | ty::TyFnDef(def_id, |
a7813a04 XL |
536 | substs.fold_with(folder), |
537 | f.fold_with(folder)) | |
9cc50fc6 | 538 | } |
a7813a04 XL |
539 | ty::TyFnPtr(f) => ty::TyFnPtr(f.fold_with(folder)), |
540 | ty::TyRef(ref r, tm) => { | |
541 | ty::TyRef(r.fold_with(folder), tm.fold_with(folder)) | |
9cc50fc6 | 542 | } |
a7813a04 | 543 | ty::TyClosure(did, substs) => ty::TyClosure(did, substs.fold_with(folder)), |
9cc50fc6 | 544 | ty::TyProjection(ref data) => ty::TyProjection(data.fold_with(folder)), |
5bcae85e | 545 | ty::TyAnon(did, substs) => ty::TyAnon(did, substs.fold_with(folder)), |
9cc50fc6 SL |
546 | ty::TyBool | ty::TyChar | ty::TyStr | ty::TyInt(_) | |
547 | ty::TyUint(_) | ty::TyFloat(_) | ty::TyError | ty::TyInfer(_) | | |
476ff2be | 548 | ty::TyParam(..) | ty::TyNever => return self |
9cc50fc6 | 549 | }; |
476ff2be SL |
550 | |
551 | if self.sty == sty { | |
552 | self | |
553 | } else { | |
554 | folder.tcx().mk_ty(sty) | |
555 | } | |
9cc50fc6 SL |
556 | } |
557 | ||
a7813a04 | 558 | fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
e9174d1e SL |
559 | folder.fold_ty(*self) |
560 | } | |
9cc50fc6 SL |
561 | |
562 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
563 | match self.sty { | |
9cc50fc6 SL |
564 | ty::TyRawPtr(ref tm) => tm.visit_with(visitor), |
565 | ty::TyArray(typ, _sz) => typ.visit_with(visitor), | |
566 | ty::TySlice(typ) => typ.visit_with(visitor), | |
9e0c209e | 567 | ty::TyAdt(_, substs) => substs.visit_with(visitor), |
476ff2be SL |
568 | ty::TyDynamic(ref trait_ty, ref reg) => |
569 | trait_ty.visit_with(visitor) || reg.visit_with(visitor), | |
8bb4bdeb | 570 | ty::TyTuple(ts, _) => ts.visit_with(visitor), |
54a0048b SL |
571 | ty::TyFnDef(_, substs, ref f) => { |
572 | substs.visit_with(visitor) || f.visit_with(visitor) | |
573 | } | |
574 | ty::TyFnPtr(ref f) => f.visit_with(visitor), | |
9cc50fc6 | 575 | ty::TyRef(r, ref tm) => r.visit_with(visitor) || tm.visit_with(visitor), |
9cc50fc6 SL |
576 | ty::TyClosure(_did, ref substs) => substs.visit_with(visitor), |
577 | ty::TyProjection(ref data) => data.visit_with(visitor), | |
5bcae85e | 578 | ty::TyAnon(_, ref substs) => substs.visit_with(visitor), |
9cc50fc6 SL |
579 | ty::TyBool | ty::TyChar | ty::TyStr | ty::TyInt(_) | |
580 | ty::TyUint(_) | ty::TyFloat(_) | ty::TyError | ty::TyInfer(_) | | |
5bcae85e | 581 | ty::TyParam(..) | ty::TyNever => false, |
9cc50fc6 SL |
582 | } |
583 | } | |
584 | ||
585 | fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
586 | visitor.visit_ty(self) | |
587 | } | |
e9174d1e SL |
588 | } |
589 | ||
e9174d1e | 590 | impl<'tcx> TypeFoldable<'tcx> for ty::TypeAndMut<'tcx> { |
a7813a04 | 591 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
9cc50fc6 SL |
592 | ty::TypeAndMut { ty: self.ty.fold_with(folder), mutbl: self.mutbl } |
593 | } | |
594 | ||
9cc50fc6 SL |
595 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { |
596 | self.ty.visit_with(visitor) | |
597 | } | |
e9174d1e SL |
598 | } |
599 | ||
e9174d1e | 600 | impl<'tcx> TypeFoldable<'tcx> for ty::FnSig<'tcx> { |
a7813a04 | 601 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
476ff2be SL |
602 | let inputs_and_output = self.inputs_and_output.fold_with(folder); |
603 | ty::FnSig { | |
604 | inputs_and_output: folder.tcx().intern_type_list(&inputs_and_output), | |
605 | variadic: self.variadic, | |
8bb4bdeb XL |
606 | unsafety: self.unsafety, |
607 | abi: self.abi, | |
476ff2be | 608 | } |
9cc50fc6 SL |
609 | } |
610 | ||
9cc50fc6 | 611 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { |
476ff2be SL |
612 | self.inputs().iter().any(|i| i.visit_with(visitor)) || |
613 | self.output().visit_with(visitor) | |
9cc50fc6 | 614 | } |
e9174d1e SL |
615 | } |
616 | ||
617 | impl<'tcx> TypeFoldable<'tcx> for ty::TraitRef<'tcx> { | |
a7813a04 | 618 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
9cc50fc6 SL |
619 | ty::TraitRef { |
620 | def_id: self.def_id, | |
a7813a04 | 621 | substs: self.substs.fold_with(folder), |
9cc50fc6 SL |
622 | } |
623 | } | |
624 | ||
9e0c209e SL |
625 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { |
626 | self.substs.visit_with(visitor) | |
627 | } | |
476ff2be SL |
628 | |
629 | fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
630 | visitor.visit_trait_ref(*self) | |
631 | } | |
9e0c209e SL |
632 | } |
633 | ||
634 | impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialTraitRef<'tcx> { | |
635 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { | |
636 | ty::ExistentialTraitRef { | |
637 | def_id: self.def_id, | |
638 | substs: self.substs.fold_with(folder), | |
639 | } | |
e9174d1e | 640 | } |
9cc50fc6 SL |
641 | |
642 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
643 | self.substs.visit_with(visitor) | |
644 | } | |
e9174d1e SL |
645 | } |
646 | ||
54a0048b | 647 | impl<'tcx> TypeFoldable<'tcx> for ty::ImplHeader<'tcx> { |
a7813a04 | 648 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
54a0048b SL |
649 | ty::ImplHeader { |
650 | impl_def_id: self.impl_def_id, | |
651 | self_ty: self.self_ty.fold_with(folder), | |
652 | trait_ref: self.trait_ref.map(|t| t.fold_with(folder)), | |
653 | predicates: self.predicates.iter().map(|p| p.fold_with(folder)).collect(), | |
654 | } | |
655 | } | |
656 | ||
54a0048b SL |
657 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { |
658 | self.self_ty.visit_with(visitor) || | |
659 | self.trait_ref.map(|r| r.visit_with(visitor)).unwrap_or(false) || | |
660 | self.predicates.iter().any(|p| p.visit_with(visitor)) | |
661 | } | |
662 | } | |
663 | ||
7cac9316 | 664 | impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> { |
a7813a04 | 665 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, _folder: &mut F) -> Self { |
9cc50fc6 SL |
666 | *self |
667 | } | |
668 | ||
a7813a04 | 669 | fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
e9174d1e SL |
670 | folder.fold_region(*self) |
671 | } | |
9cc50fc6 SL |
672 | |
673 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> bool { | |
674 | false | |
675 | } | |
676 | ||
677 | fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
678 | visitor.visit_region(*self) | |
679 | } | |
e9174d1e SL |
680 | } |
681 | ||
e9174d1e | 682 | impl<'tcx> TypeFoldable<'tcx> for ty::ClosureSubsts<'tcx> { |
a7813a04 | 683 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
e9174d1e | 684 | ty::ClosureSubsts { |
476ff2be | 685 | substs: self.substs.fold_with(folder), |
e9174d1e SL |
686 | } |
687 | } | |
9cc50fc6 SL |
688 | |
689 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
476ff2be | 690 | self.substs.visit_with(visitor) |
9cc50fc6 | 691 | } |
e9174d1e SL |
692 | } |
693 | ||
7cac9316 | 694 | impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::Adjustment<'tcx> { |
a7813a04 | 695 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
7cac9316 XL |
696 | ty::adjustment::Adjustment { |
697 | kind: self.kind.fold_with(folder), | |
698 | target: self.target.fold_with(folder), | |
e9174d1e SL |
699 | } |
700 | } | |
9cc50fc6 SL |
701 | |
702 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
7cac9316 XL |
703 | self.kind.visit_with(visitor) || |
704 | self.target.visit_with(visitor) | |
705 | } | |
706 | } | |
707 | ||
708 | impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::Adjust<'tcx> { | |
709 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { | |
710 | match *self { | |
711 | ty::adjustment::Adjust::NeverToAny | | |
712 | ty::adjustment::Adjust::ReifyFnPointer | | |
713 | ty::adjustment::Adjust::UnsafeFnPointer | | |
714 | ty::adjustment::Adjust::ClosureFnPointer | | |
715 | ty::adjustment::Adjust::MutToConstPointer | | |
716 | ty::adjustment::Adjust::Unsize => self.clone(), | |
717 | ty::adjustment::Adjust::Deref(ref overloaded) => { | |
718 | ty::adjustment::Adjust::Deref(overloaded.fold_with(folder)) | |
719 | } | |
720 | ty::adjustment::Adjust::Borrow(ref autoref) => { | |
721 | ty::adjustment::Adjust::Borrow(autoref.fold_with(folder)) | |
722 | } | |
723 | } | |
724 | } | |
725 | ||
726 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
727 | match *self { | |
728 | ty::adjustment::Adjust::NeverToAny | | |
729 | ty::adjustment::Adjust::ReifyFnPointer | | |
730 | ty::adjustment::Adjust::UnsafeFnPointer | | |
731 | ty::adjustment::Adjust::ClosureFnPointer | | |
732 | ty::adjustment::Adjust::MutToConstPointer | | |
733 | ty::adjustment::Adjust::Unsize => false, | |
734 | ty::adjustment::Adjust::Deref(ref overloaded) => { | |
735 | overloaded.visit_with(visitor) | |
736 | } | |
737 | ty::adjustment::Adjust::Borrow(ref autoref) => { | |
738 | autoref.visit_with(visitor) | |
739 | } | |
740 | } | |
741 | } | |
742 | } | |
743 | ||
744 | impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::OverloadedDeref<'tcx> { | |
745 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { | |
746 | ty::adjustment::OverloadedDeref { | |
747 | region: self.region.fold_with(folder), | |
748 | mutbl: self.mutbl, | |
749 | } | |
750 | } | |
751 | ||
752 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
753 | self.region.visit_with(visitor) | |
9cc50fc6 | 754 | } |
e9174d1e SL |
755 | } |
756 | ||
c30ab7b3 | 757 | impl<'tcx> TypeFoldable<'tcx> for ty::adjustment::AutoBorrow<'tcx> { |
a7813a04 | 758 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
9cc50fc6 | 759 | match *self { |
c30ab7b3 SL |
760 | ty::adjustment::AutoBorrow::Ref(ref r, m) => { |
761 | ty::adjustment::AutoBorrow::Ref(r.fold_with(folder), m) | |
9cc50fc6 | 762 | } |
c30ab7b3 | 763 | ty::adjustment::AutoBorrow::RawPtr(m) => ty::adjustment::AutoBorrow::RawPtr(m) |
9cc50fc6 SL |
764 | } |
765 | } | |
766 | ||
9cc50fc6 SL |
767 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { |
768 | match *self { | |
c30ab7b3 SL |
769 | ty::adjustment::AutoBorrow::Ref(r, _m) => r.visit_with(visitor), |
770 | ty::adjustment::AutoBorrow::RawPtr(_m) => false, | |
9cc50fc6 SL |
771 | } |
772 | } | |
e9174d1e SL |
773 | } |
774 | ||
476ff2be SL |
775 | impl<'tcx> TypeFoldable<'tcx> for ty::GenericPredicates<'tcx> { |
776 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { | |
777 | ty::GenericPredicates { | |
778 | parent: self.parent, | |
779 | predicates: self.predicates.fold_with(folder), | |
780 | } | |
781 | } | |
782 | ||
783 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
784 | self.predicates.visit_with(visitor) | |
785 | } | |
786 | } | |
787 | ||
7cac9316 XL |
788 | impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Slice<ty::Predicate<'tcx>> { |
789 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { | |
790 | let v = self.iter().map(|p| p.fold_with(folder)).collect::<AccumulateVec<[_; 8]>>(); | |
791 | folder.tcx().intern_predicates(&v) | |
792 | } | |
793 | ||
794 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
795 | self.iter().any(|p| p.visit_with(visitor)) | |
796 | } | |
797 | } | |
798 | ||
e9174d1e | 799 | impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> { |
a7813a04 | 800 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
e9174d1e SL |
801 | match *self { |
802 | ty::Predicate::Trait(ref a) => | |
803 | ty::Predicate::Trait(a.fold_with(folder)), | |
804 | ty::Predicate::Equate(ref binder) => | |
805 | ty::Predicate::Equate(binder.fold_with(folder)), | |
cc61c64b XL |
806 | ty::Predicate::Subtype(ref binder) => |
807 | ty::Predicate::Subtype(binder.fold_with(folder)), | |
e9174d1e SL |
808 | ty::Predicate::RegionOutlives(ref binder) => |
809 | ty::Predicate::RegionOutlives(binder.fold_with(folder)), | |
810 | ty::Predicate::TypeOutlives(ref binder) => | |
811 | ty::Predicate::TypeOutlives(binder.fold_with(folder)), | |
812 | ty::Predicate::Projection(ref binder) => | |
813 | ty::Predicate::Projection(binder.fold_with(folder)), | |
814 | ty::Predicate::WellFormed(data) => | |
815 | ty::Predicate::WellFormed(data.fold_with(folder)), | |
a7813a04 XL |
816 | ty::Predicate::ClosureKind(closure_def_id, kind) => |
817 | ty::Predicate::ClosureKind(closure_def_id, kind), | |
e9174d1e SL |
818 | ty::Predicate::ObjectSafe(trait_def_id) => |
819 | ty::Predicate::ObjectSafe(trait_def_id), | |
820 | } | |
821 | } | |
9cc50fc6 SL |
822 | |
823 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
824 | match *self { | |
825 | ty::Predicate::Trait(ref a) => a.visit_with(visitor), | |
826 | ty::Predicate::Equate(ref binder) => binder.visit_with(visitor), | |
cc61c64b | 827 | ty::Predicate::Subtype(ref binder) => binder.visit_with(visitor), |
9cc50fc6 SL |
828 | ty::Predicate::RegionOutlives(ref binder) => binder.visit_with(visitor), |
829 | ty::Predicate::TypeOutlives(ref binder) => binder.visit_with(visitor), | |
830 | ty::Predicate::Projection(ref binder) => binder.visit_with(visitor), | |
831 | ty::Predicate::WellFormed(data) => data.visit_with(visitor), | |
a7813a04 | 832 | ty::Predicate::ClosureKind(_closure_def_id, _kind) => false, |
9cc50fc6 SL |
833 | ty::Predicate::ObjectSafe(_trait_def_id) => false, |
834 | } | |
835 | } | |
e9174d1e SL |
836 | } |
837 | ||
838 | impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionPredicate<'tcx> { | |
a7813a04 | 839 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
e9174d1e SL |
840 | ty::ProjectionPredicate { |
841 | projection_ty: self.projection_ty.fold_with(folder), | |
842 | ty: self.ty.fold_with(folder), | |
843 | } | |
844 | } | |
9cc50fc6 SL |
845 | |
846 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
847 | self.projection_ty.visit_with(visitor) || self.ty.visit_with(visitor) | |
848 | } | |
e9174d1e SL |
849 | } |
850 | ||
9e0c209e SL |
851 | impl<'tcx> TypeFoldable<'tcx> for ty::ExistentialProjection<'tcx> { |
852 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { | |
853 | ty::ExistentialProjection { | |
854 | trait_ref: self.trait_ref.fold_with(folder), | |
855 | item_name: self.item_name, | |
856 | ty: self.ty.fold_with(folder), | |
857 | } | |
858 | } | |
859 | ||
860 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
861 | self.trait_ref.visit_with(visitor) || self.ty.visit_with(visitor) | |
862 | } | |
863 | } | |
864 | ||
e9174d1e | 865 | impl<'tcx> TypeFoldable<'tcx> for ty::ProjectionTy<'tcx> { |
a7813a04 | 866 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
e9174d1e SL |
867 | ty::ProjectionTy { |
868 | trait_ref: self.trait_ref.fold_with(folder), | |
7cac9316 | 869 | item_def_id: self.item_def_id, |
e9174d1e SL |
870 | } |
871 | } | |
9cc50fc6 SL |
872 | |
873 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
874 | self.trait_ref.visit_with(visitor) | |
875 | } | |
e9174d1e SL |
876 | } |
877 | ||
878 | impl<'tcx> TypeFoldable<'tcx> for ty::InstantiatedPredicates<'tcx> { | |
a7813a04 | 879 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
e9174d1e SL |
880 | ty::InstantiatedPredicates { |
881 | predicates: self.predicates.fold_with(folder), | |
882 | } | |
883 | } | |
9cc50fc6 SL |
884 | |
885 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
886 | self.predicates.visit_with(visitor) | |
887 | } | |
e9174d1e SL |
888 | } |
889 | ||
890 | impl<'tcx> TypeFoldable<'tcx> for ty::EquatePredicate<'tcx> { | |
a7813a04 | 891 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
cc61c64b | 892 | ty::EquatePredicate(self.0.fold_with(folder), self.1.fold_with(folder)) |
e9174d1e | 893 | } |
9cc50fc6 SL |
894 | |
895 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
896 | self.0.visit_with(visitor) || self.1.visit_with(visitor) | |
897 | } | |
e9174d1e SL |
898 | } |
899 | ||
cc61c64b XL |
900 | impl<'tcx> TypeFoldable<'tcx> for ty::SubtypePredicate<'tcx> { |
901 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { | |
902 | ty::SubtypePredicate { | |
903 | a_is_expected: self.a_is_expected, | |
904 | a: self.a.fold_with(folder), | |
905 | b: self.b.fold_with(folder) | |
906 | } | |
907 | } | |
908 | ||
909 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
910 | self.a.visit_with(visitor) || self.b.visit_with(visitor) | |
911 | } | |
912 | } | |
913 | ||
e9174d1e | 914 | impl<'tcx> TypeFoldable<'tcx> for ty::TraitPredicate<'tcx> { |
a7813a04 | 915 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
e9174d1e SL |
916 | ty::TraitPredicate { |
917 | trait_ref: self.trait_ref.fold_with(folder) | |
918 | } | |
919 | } | |
9cc50fc6 SL |
920 | |
921 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
922 | self.trait_ref.visit_with(visitor) | |
923 | } | |
e9174d1e SL |
924 | } |
925 | ||
926 | impl<'tcx,T,U> TypeFoldable<'tcx> for ty::OutlivesPredicate<T,U> | |
927 | where T : TypeFoldable<'tcx>, | |
928 | U : TypeFoldable<'tcx>, | |
929 | { | |
a7813a04 | 930 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
e9174d1e SL |
931 | ty::OutlivesPredicate(self.0.fold_with(folder), |
932 | self.1.fold_with(folder)) | |
933 | } | |
9cc50fc6 SL |
934 | |
935 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
936 | self.0.visit_with(visitor) || self.1.visit_with(visitor) | |
937 | } | |
e9174d1e SL |
938 | } |
939 | ||
940 | impl<'tcx> TypeFoldable<'tcx> for ty::ClosureUpvar<'tcx> { | |
a7813a04 | 941 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { |
e9174d1e SL |
942 | ty::ClosureUpvar { |
943 | def: self.def, | |
944 | span: self.span, | |
945 | ty: self.ty.fold_with(folder), | |
946 | } | |
947 | } | |
9cc50fc6 SL |
948 | |
949 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
950 | self.ty.visit_with(visitor) | |
951 | } | |
e9174d1e SL |
952 | } |
953 | ||
5bcae85e SL |
954 | impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::error::ExpectedFound<T> { |
955 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { | |
956 | ty::error::ExpectedFound { | |
957 | expected: self.expected.fold_with(folder), | |
958 | found: self.found.fold_with(folder), | |
959 | } | |
960 | } | |
961 | ||
962 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
963 | self.expected.visit_with(visitor) || self.found.visit_with(visitor) | |
964 | } | |
965 | } | |
8bb4bdeb XL |
966 | |
967 | impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T> { | |
968 | fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { | |
969 | self.iter().map(|x| x.fold_with(folder)).collect() | |
970 | } | |
971 | ||
972 | fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool { | |
973 | self.iter().any(|t| t.visit_with(visitor)) | |
974 | } | |
975 | } |