|
1 | 1 | use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; |
2 | | -use rustc_serialize::Decoder; |
3 | | -use rustc_serialize::{Decodable, Encodable}; |
4 | 2 | use std::fmt; |
5 | 3 | use std::ops::ControlFlow; |
6 | 4 |
|
7 | 5 | use crate::fold::{FallibleTypeFolder, TypeFoldable}; |
8 | 6 | use crate::visit::{TypeVisitable, TypeVisitor}; |
9 | 7 | use crate::{HashStableContext, Interner}; |
10 | | -use crate::{TyDecoder, TyEncoder}; |
11 | 8 |
|
12 | 9 | /// A clause is something that can appear in where bounds or be inferred |
13 | 10 | /// by implied bounds. |
14 | 11 | #[derive(derivative::Derivative)] |
15 | 12 | #[derivative(Clone(bound = ""), Hash(bound = ""))] |
| 13 | +#[derive(TyEncodable, TyDecodable)] |
16 | 14 | pub enum ClauseKind<I: Interner> { |
17 | 15 | /// Corresponds to `where Foo: Bar<A, B, C>`. `Foo` here would be |
18 | 16 | /// the `Self` type of the trait reference and `A`, `B`, and `C` |
@@ -161,65 +159,9 @@ where |
161 | 159 | } |
162 | 160 | } |
163 | 161 |
|
164 | | -impl<I: Interner, D: TyDecoder<I = I>> Decodable<D> for ClauseKind<I> |
165 | | -where |
166 | | - I::Ty: Decodable<D>, |
167 | | - I::Const: Decodable<D>, |
168 | | - I::GenericArg: Decodable<D>, |
169 | | - I::TraitPredicate: Decodable<D>, |
170 | | - I::ProjectionPredicate: Decodable<D>, |
171 | | - I::TypeOutlivesPredicate: Decodable<D>, |
172 | | - I::RegionOutlivesPredicate: Decodable<D>, |
173 | | -{ |
174 | | - fn decode(d: &mut D) -> Self { |
175 | | - match Decoder::read_usize(d) { |
176 | | - 0 => ClauseKind::Trait(Decodable::decode(d)), |
177 | | - 1 => ClauseKind::RegionOutlives(Decodable::decode(d)), |
178 | | - 2 => ClauseKind::TypeOutlives(Decodable::decode(d)), |
179 | | - 3 => ClauseKind::Projection(Decodable::decode(d)), |
180 | | - 4 => ClauseKind::ConstArgHasType(Decodable::decode(d), Decodable::decode(d)), |
181 | | - 5 => ClauseKind::WellFormed(Decodable::decode(d)), |
182 | | - 6 => ClauseKind::ConstEvaluatable(Decodable::decode(d)), |
183 | | - _ => panic!( |
184 | | - "{}", |
185 | | - format!( |
186 | | - "invalid enum variant tag while decoding `{}`, expected 0..{}", |
187 | | - "ClauseKind", 7, |
188 | | - ) |
189 | | - ), |
190 | | - } |
191 | | - } |
192 | | -} |
193 | | - |
194 | | -impl<I: Interner, E: TyEncoder> Encodable<E> for ClauseKind<I> |
195 | | -where |
196 | | - I::Ty: Encodable<E>, |
197 | | - I::Const: Encodable<E>, |
198 | | - I::GenericArg: Encodable<E>, |
199 | | - I::TraitPredicate: Encodable<E>, |
200 | | - I::ProjectionPredicate: Encodable<E>, |
201 | | - I::TypeOutlivesPredicate: Encodable<E>, |
202 | | - I::RegionOutlivesPredicate: Encodable<E>, |
203 | | -{ |
204 | | - fn encode(&self, s: &mut E) { |
205 | | - let discriminant = clause_kind_discriminant(self); |
206 | | - match self { |
207 | | - ClauseKind::Trait(p) => s.emit_enum_variant(discriminant, |s| p.encode(s)), |
208 | | - ClauseKind::RegionOutlives(p) => s.emit_enum_variant(discriminant, |s| p.encode(s)), |
209 | | - ClauseKind::TypeOutlives(p) => s.emit_enum_variant(discriminant, |s| p.encode(s)), |
210 | | - ClauseKind::Projection(p) => s.emit_enum_variant(discriminant, |s| p.encode(s)), |
211 | | - ClauseKind::ConstArgHasType(c, t) => s.emit_enum_variant(discriminant, |s| { |
212 | | - c.encode(s); |
213 | | - t.encode(s); |
214 | | - }), |
215 | | - ClauseKind::WellFormed(p) => s.emit_enum_variant(discriminant, |s| p.encode(s)), |
216 | | - ClauseKind::ConstEvaluatable(p) => s.emit_enum_variant(discriminant, |s| p.encode(s)), |
217 | | - } |
218 | | - } |
219 | | -} |
220 | | - |
221 | 162 | #[derive(derivative::Derivative)] |
222 | 163 | #[derivative(Clone(bound = ""), Hash(bound = ""))] |
| 164 | +#[derive(TyEncodable, TyDecodable)] |
223 | 165 | pub enum PredicateKind<I: Interner> { |
224 | 166 | /// Prove a clause |
225 | 167 | Clause(ClauseKind<I>), |
@@ -418,83 +360,6 @@ where |
418 | 360 | } |
419 | 361 | } |
420 | 362 |
|
421 | | -impl<I: Interner, D: TyDecoder<I = I>> Decodable<D> for PredicateKind<I> |
422 | | -where |
423 | | - I::DefId: Decodable<D>, |
424 | | - I::Const: Decodable<D>, |
425 | | - I::GenericArgs: Decodable<D>, |
426 | | - I::Term: Decodable<D>, |
427 | | - I::CoercePredicate: Decodable<D>, |
428 | | - I::SubtypePredicate: Decodable<D>, |
429 | | - I::ClosureKind: Decodable<D>, |
430 | | - ClauseKind<I>: Decodable<D>, |
431 | | -{ |
432 | | - fn decode(d: &mut D) -> Self { |
433 | | - match Decoder::read_usize(d) { |
434 | | - 0 => PredicateKind::Clause(Decodable::decode(d)), |
435 | | - 1 => PredicateKind::ObjectSafe(Decodable::decode(d)), |
436 | | - 2 => PredicateKind::ClosureKind( |
437 | | - Decodable::decode(d), |
438 | | - Decodable::decode(d), |
439 | | - Decodable::decode(d), |
440 | | - ), |
441 | | - 3 => PredicateKind::Subtype(Decodable::decode(d)), |
442 | | - 4 => PredicateKind::Coerce(Decodable::decode(d)), |
443 | | - 5 => PredicateKind::ConstEquate(Decodable::decode(d), Decodable::decode(d)), |
444 | | - 6 => PredicateKind::Ambiguous, |
445 | | - 7 => PredicateKind::AliasRelate( |
446 | | - Decodable::decode(d), |
447 | | - Decodable::decode(d), |
448 | | - Decodable::decode(d), |
449 | | - ), |
450 | | - _ => panic!( |
451 | | - "{}", |
452 | | - format!( |
453 | | - "invalid enum variant tag while decoding `{}`, expected 0..{}", |
454 | | - "PredicateKind", 8, |
455 | | - ) |
456 | | - ), |
457 | | - } |
458 | | - } |
459 | | -} |
460 | | - |
461 | | -impl<I: Interner, E: TyEncoder> Encodable<E> for PredicateKind<I> |
462 | | -where |
463 | | - I::DefId: Encodable<E>, |
464 | | - I::Const: Encodable<E>, |
465 | | - I::GenericArgs: Encodable<E>, |
466 | | - I::Term: Encodable<E>, |
467 | | - I::CoercePredicate: Encodable<E>, |
468 | | - I::SubtypePredicate: Encodable<E>, |
469 | | - I::ClosureKind: Encodable<E>, |
470 | | - ClauseKind<I>: Encodable<E>, |
471 | | -{ |
472 | | - fn encode(&self, s: &mut E) { |
473 | | - let discriminant = predicate_kind_discriminant(self); |
474 | | - match self { |
475 | | - PredicateKind::Clause(c) => s.emit_enum_variant(discriminant, |s| c.encode(s)), |
476 | | - PredicateKind::ObjectSafe(d) => s.emit_enum_variant(discriminant, |s| d.encode(s)), |
477 | | - PredicateKind::ClosureKind(d, g, k) => s.emit_enum_variant(discriminant, |s| { |
478 | | - d.encode(s); |
479 | | - g.encode(s); |
480 | | - k.encode(s); |
481 | | - }), |
482 | | - PredicateKind::Subtype(c) => s.emit_enum_variant(discriminant, |s| c.encode(s)), |
483 | | - PredicateKind::Coerce(c) => s.emit_enum_variant(discriminant, |s| c.encode(s)), |
484 | | - PredicateKind::ConstEquate(a, b) => s.emit_enum_variant(discriminant, |s| { |
485 | | - a.encode(s); |
486 | | - b.encode(s); |
487 | | - }), |
488 | | - PredicateKind::Ambiguous => s.emit_enum_variant(discriminant, |_s| {}), |
489 | | - PredicateKind::AliasRelate(a, b, d) => s.emit_enum_variant(discriminant, |s| { |
490 | | - a.encode(s); |
491 | | - b.encode(s); |
492 | | - d.encode(s); |
493 | | - }), |
494 | | - } |
495 | | - } |
496 | | -} |
497 | | - |
498 | 363 | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)] |
499 | 364 | #[derive(HashStable_Generic, Encodable, Decodable)] |
500 | 365 | pub enum AliasRelationDirection { |
|
0 commit comments