|
1 | 1 | use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; |
2 | 2 | use std::fmt; |
3 | | -use std::ops::ControlFlow; |
4 | 3 |
|
5 | | -use crate::fold::{FallibleTypeFolder, TypeFoldable}; |
6 | | -use crate::visit::{TypeVisitable, TypeVisitor}; |
7 | 4 | use crate::{HashStableContext, Interner}; |
8 | 5 |
|
9 | 6 | /// A clause is something that can appear in where bounds or be inferred |
10 | 7 | /// by implied bounds. |
11 | | -#[derive(derivative::Derivative)] |
| 8 | +#[derive(derivative::Derivative, TypeFoldable, TypeVisitable)] |
12 | 9 | #[derivative(Clone(bound = ""), Hash(bound = ""))] |
13 | 10 | #[derive(TyEncodable, TyDecodable)] |
14 | 11 | pub enum ClauseKind<I: Interner> { |
@@ -106,60 +103,7 @@ where |
106 | 103 | } |
107 | 104 | } |
108 | 105 |
|
109 | | -impl<I: Interner> TypeFoldable<I> for ClauseKind<I> |
110 | | -where |
111 | | - I::Ty: TypeFoldable<I>, |
112 | | - I::Const: TypeFoldable<I>, |
113 | | - I::GenericArg: TypeFoldable<I>, |
114 | | - I::TraitPredicate: TypeFoldable<I>, |
115 | | - I::ProjectionPredicate: TypeFoldable<I>, |
116 | | - I::TypeOutlivesPredicate: TypeFoldable<I>, |
117 | | - I::RegionOutlivesPredicate: TypeFoldable<I>, |
118 | | -{ |
119 | | - fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> { |
120 | | - Ok(match self { |
121 | | - ClauseKind::Trait(p) => ClauseKind::Trait(p.try_fold_with(folder)?), |
122 | | - ClauseKind::RegionOutlives(p) => ClauseKind::RegionOutlives(p.try_fold_with(folder)?), |
123 | | - ClauseKind::TypeOutlives(p) => ClauseKind::TypeOutlives(p.try_fold_with(folder)?), |
124 | | - ClauseKind::Projection(p) => ClauseKind::Projection(p.try_fold_with(folder)?), |
125 | | - ClauseKind::ConstArgHasType(c, t) => { |
126 | | - ClauseKind::ConstArgHasType(c.try_fold_with(folder)?, t.try_fold_with(folder)?) |
127 | | - } |
128 | | - ClauseKind::WellFormed(p) => ClauseKind::WellFormed(p.try_fold_with(folder)?), |
129 | | - ClauseKind::ConstEvaluatable(p) => { |
130 | | - ClauseKind::ConstEvaluatable(p.try_fold_with(folder)?) |
131 | | - } |
132 | | - }) |
133 | | - } |
134 | | -} |
135 | | - |
136 | | -impl<I: Interner> TypeVisitable<I> for ClauseKind<I> |
137 | | -where |
138 | | - I::Ty: TypeVisitable<I>, |
139 | | - I::Const: TypeVisitable<I>, |
140 | | - I::GenericArg: TypeVisitable<I>, |
141 | | - I::TraitPredicate: TypeVisitable<I>, |
142 | | - I::ProjectionPredicate: TypeVisitable<I>, |
143 | | - I::TypeOutlivesPredicate: TypeVisitable<I>, |
144 | | - I::RegionOutlivesPredicate: TypeVisitable<I>, |
145 | | -{ |
146 | | - fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> { |
147 | | - match self { |
148 | | - ClauseKind::Trait(p) => p.visit_with(visitor), |
149 | | - ClauseKind::RegionOutlives(p) => p.visit_with(visitor), |
150 | | - ClauseKind::TypeOutlives(p) => p.visit_with(visitor), |
151 | | - ClauseKind::Projection(p) => p.visit_with(visitor), |
152 | | - ClauseKind::ConstArgHasType(c, t) => { |
153 | | - c.visit_with(visitor)?; |
154 | | - t.visit_with(visitor) |
155 | | - } |
156 | | - ClauseKind::WellFormed(p) => p.visit_with(visitor), |
157 | | - ClauseKind::ConstEvaluatable(p) => p.visit_with(visitor), |
158 | | - } |
159 | | - } |
160 | | -} |
161 | | - |
162 | | -#[derive(derivative::Derivative)] |
| 106 | +#[derive(derivative::Derivative, TypeFoldable, TypeVisitable)] |
163 | 107 | #[derivative(Clone(bound = ""), Hash(bound = ""))] |
164 | 108 | #[derive(TyEncodable, TyDecodable)] |
165 | 109 | pub enum PredicateKind<I: Interner> { |
@@ -289,77 +233,6 @@ where |
289 | 233 | } |
290 | 234 | } |
291 | 235 |
|
292 | | -impl<I: Interner> TypeFoldable<I> for PredicateKind<I> |
293 | | -where |
294 | | - I::DefId: TypeFoldable<I>, |
295 | | - I::Const: TypeFoldable<I>, |
296 | | - I::GenericArgs: TypeFoldable<I>, |
297 | | - I::Term: TypeFoldable<I>, |
298 | | - I::CoercePredicate: TypeFoldable<I>, |
299 | | - I::SubtypePredicate: TypeFoldable<I>, |
300 | | - I::ClosureKind: TypeFoldable<I>, |
301 | | - ClauseKind<I>: TypeFoldable<I>, |
302 | | -{ |
303 | | - fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> { |
304 | | - Ok(match self { |
305 | | - PredicateKind::Clause(c) => PredicateKind::Clause(c.try_fold_with(folder)?), |
306 | | - PredicateKind::ObjectSafe(d) => PredicateKind::ObjectSafe(d.try_fold_with(folder)?), |
307 | | - PredicateKind::ClosureKind(d, g, k) => PredicateKind::ClosureKind( |
308 | | - d.try_fold_with(folder)?, |
309 | | - g.try_fold_with(folder)?, |
310 | | - k.try_fold_with(folder)?, |
311 | | - ), |
312 | | - PredicateKind::Subtype(s) => PredicateKind::Subtype(s.try_fold_with(folder)?), |
313 | | - PredicateKind::Coerce(s) => PredicateKind::Coerce(s.try_fold_with(folder)?), |
314 | | - PredicateKind::ConstEquate(a, b) => { |
315 | | - PredicateKind::ConstEquate(a.try_fold_with(folder)?, b.try_fold_with(folder)?) |
316 | | - } |
317 | | - PredicateKind::Ambiguous => PredicateKind::Ambiguous, |
318 | | - PredicateKind::AliasRelate(a, b, d) => PredicateKind::AliasRelate( |
319 | | - a.try_fold_with(folder)?, |
320 | | - b.try_fold_with(folder)?, |
321 | | - d.try_fold_with(folder)?, |
322 | | - ), |
323 | | - }) |
324 | | - } |
325 | | -} |
326 | | - |
327 | | -impl<I: Interner> TypeVisitable<I> for PredicateKind<I> |
328 | | -where |
329 | | - I::DefId: TypeVisitable<I>, |
330 | | - I::Const: TypeVisitable<I>, |
331 | | - I::GenericArgs: TypeVisitable<I>, |
332 | | - I::Term: TypeVisitable<I>, |
333 | | - I::CoercePredicate: TypeVisitable<I>, |
334 | | - I::SubtypePredicate: TypeVisitable<I>, |
335 | | - I::ClosureKind: TypeVisitable<I>, |
336 | | - ClauseKind<I>: TypeVisitable<I>, |
337 | | -{ |
338 | | - fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> { |
339 | | - match self { |
340 | | - PredicateKind::Clause(p) => p.visit_with(visitor), |
341 | | - PredicateKind::ObjectSafe(d) => d.visit_with(visitor), |
342 | | - PredicateKind::ClosureKind(d, g, k) => { |
343 | | - d.visit_with(visitor)?; |
344 | | - g.visit_with(visitor)?; |
345 | | - k.visit_with(visitor) |
346 | | - } |
347 | | - PredicateKind::Subtype(s) => s.visit_with(visitor), |
348 | | - PredicateKind::Coerce(s) => s.visit_with(visitor), |
349 | | - PredicateKind::ConstEquate(a, b) => { |
350 | | - a.visit_with(visitor)?; |
351 | | - b.visit_with(visitor) |
352 | | - } |
353 | | - PredicateKind::Ambiguous => ControlFlow::Continue(()), |
354 | | - PredicateKind::AliasRelate(a, b, d) => { |
355 | | - a.visit_with(visitor)?; |
356 | | - b.visit_with(visitor)?; |
357 | | - d.visit_with(visitor) |
358 | | - } |
359 | | - } |
360 | | - } |
361 | | -} |
362 | | - |
363 | 236 | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)] |
364 | 237 | #[derive(HashStable_Generic, Encodable, Decodable)] |
365 | 238 | pub enum AliasRelationDirection { |
|
0 commit comments