@@ -2,7 +2,6 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2
2
use rustc_serialize:: Decoder ;
3
3
use rustc_serialize:: { Decodable , Encodable } ;
4
4
use std:: fmt;
5
- use std:: hash;
6
5
use std:: ops:: ControlFlow ;
7
6
8
7
use crate :: fold:: { FallibleTypeFolder , TypeFoldable } ;
@@ -12,6 +11,8 @@ use crate::{TyDecoder, TyEncoder};
12
11
13
12
/// A clause is something that can appear in where bounds or be inferred
14
13
/// by implied bounds.
14
+ #[ derive( derivative:: Derivative ) ]
15
+ #[ derivative( Clone ( bound = "" ) , PartialEq ( bound = "" ) , Eq ( bound = "" ) , Hash ( bound = "" ) ) ]
15
16
pub enum ClauseKind < I : Interner > {
16
17
/// Corresponds to `where Foo: Bar<A, B, C>`. `Foo` here would be
17
18
/// the `Self` type of the trait reference and `A`, `B`, and `C`
@@ -39,20 +40,6 @@ pub enum ClauseKind<I: Interner> {
39
40
ConstEvaluatable ( I :: Const ) ,
40
41
}
41
42
42
- impl < I : Interner > Clone for ClauseKind < I > {
43
- fn clone ( & self ) -> Self {
44
- match self {
45
- Self :: Trait ( arg0) => Self :: Trait ( arg0. clone ( ) ) ,
46
- Self :: RegionOutlives ( arg0) => Self :: RegionOutlives ( arg0. clone ( ) ) ,
47
- Self :: TypeOutlives ( arg0) => Self :: TypeOutlives ( arg0. clone ( ) ) ,
48
- Self :: Projection ( arg0) => Self :: Projection ( arg0. clone ( ) ) ,
49
- Self :: ConstArgHasType ( arg0, arg1) => Self :: ConstArgHasType ( arg0. clone ( ) , arg1. clone ( ) ) ,
50
- Self :: WellFormed ( arg0) => Self :: WellFormed ( arg0. clone ( ) ) ,
51
- Self :: ConstEvaluatable ( arg0) => Self :: ConstEvaluatable ( arg0. clone ( ) ) ,
52
- }
53
- }
54
- }
55
-
56
43
impl < I : Interner > Copy for ClauseKind < I >
57
44
where
58
45
I :: Ty : Copy ,
65
52
{
66
53
}
67
54
68
- impl < I : Interner > PartialEq for ClauseKind < I > {
69
- fn eq ( & self , other : & Self ) -> bool {
70
- match ( self , other) {
71
- ( Self :: Trait ( l0) , Self :: Trait ( r0) ) => l0 == r0,
72
- ( Self :: RegionOutlives ( l0) , Self :: RegionOutlives ( r0) ) => l0 == r0,
73
- ( Self :: TypeOutlives ( l0) , Self :: TypeOutlives ( r0) ) => l0 == r0,
74
- ( Self :: Projection ( l0) , Self :: Projection ( r0) ) => l0 == r0,
75
- ( Self :: ConstArgHasType ( l0, l1) , Self :: ConstArgHasType ( r0, r1) ) => l0 == r0 && l1 == r1,
76
- ( Self :: WellFormed ( l0) , Self :: WellFormed ( r0) ) => l0 == r0,
77
- ( Self :: ConstEvaluatable ( l0) , Self :: ConstEvaluatable ( r0) ) => l0 == r0,
78
- _ => false ,
79
- }
80
- }
81
- }
82
-
83
- impl < I : Interner > Eq for ClauseKind < I > { }
84
-
85
55
fn clause_kind_discriminant < I : Interner > ( value : & ClauseKind < I > ) -> usize {
86
56
match value {
87
57
ClauseKind :: Trait ( _) => 0 ,
@@ -94,24 +64,6 @@ fn clause_kind_discriminant<I: Interner>(value: &ClauseKind<I>) -> usize {
94
64
}
95
65
}
96
66
97
- impl < I : Interner > hash:: Hash for ClauseKind < I > {
98
- fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
99
- clause_kind_discriminant ( self ) . hash ( state) ;
100
- match self {
101
- ClauseKind :: Trait ( p) => p. hash ( state) ,
102
- ClauseKind :: RegionOutlives ( p) => p. hash ( state) ,
103
- ClauseKind :: TypeOutlives ( p) => p. hash ( state) ,
104
- ClauseKind :: Projection ( p) => p. hash ( state) ,
105
- ClauseKind :: ConstArgHasType ( c, t) => {
106
- c. hash ( state) ;
107
- t. hash ( state) ;
108
- }
109
- ClauseKind :: WellFormed ( t) => t. hash ( state) ,
110
- ClauseKind :: ConstEvaluatable ( c) => c. hash ( state) ,
111
- }
112
- }
113
- }
114
-
115
67
impl < CTX : HashStableContext , I : Interner > HashStable < CTX > for ClauseKind < I >
116
68
where
117
69
I :: Ty : HashStable < CTX > ,
@@ -249,6 +201,8 @@ where
249
201
}
250
202
}
251
203
204
+ #[ derive( derivative:: Derivative ) ]
205
+ #[ derivative( Clone ( bound = "" ) , PartialEq ( bound = "" ) , Eq ( bound = "" ) , Hash ( bound = "" ) ) ]
252
206
pub enum PredicateKind < I : Interner > {
253
207
/// Prove a clause
254
208
Clause ( ClauseKind < I > ) ,
@@ -305,46 +259,6 @@ where
305
259
{
306
260
}
307
261
308
- impl < I : Interner > Clone for PredicateKind < I > {
309
- fn clone ( & self ) -> Self {
310
- match self {
311
- Self :: Clause ( arg0) => Self :: Clause ( arg0. clone ( ) ) ,
312
- Self :: ObjectSafe ( arg0) => Self :: ObjectSafe ( arg0. clone ( ) ) ,
313
- Self :: ClosureKind ( arg0, arg1, arg2) => {
314
- Self :: ClosureKind ( arg0. clone ( ) , arg1. clone ( ) , arg2. clone ( ) )
315
- }
316
- Self :: Subtype ( arg0) => Self :: Subtype ( arg0. clone ( ) ) ,
317
- Self :: Coerce ( arg0) => Self :: Coerce ( arg0. clone ( ) ) ,
318
- Self :: ConstEquate ( arg0, arg1) => Self :: ConstEquate ( arg0. clone ( ) , arg1. clone ( ) ) ,
319
- Self :: Ambiguous => Self :: Ambiguous ,
320
- Self :: AliasRelate ( arg0, arg1, arg2) => {
321
- Self :: AliasRelate ( arg0. clone ( ) , arg1. clone ( ) , arg2. clone ( ) )
322
- }
323
- }
324
- }
325
- }
326
-
327
- impl < I : Interner > PartialEq for PredicateKind < I > {
328
- fn eq ( & self , other : & Self ) -> bool {
329
- match ( self , other) {
330
- ( Self :: Clause ( l0) , Self :: Clause ( r0) ) => l0 == r0,
331
- ( Self :: ObjectSafe ( l0) , Self :: ObjectSafe ( r0) ) => l0 == r0,
332
- ( Self :: ClosureKind ( l0, l1, l2) , Self :: ClosureKind ( r0, r1, r2) ) => {
333
- l0 == r0 && l1 == r1 && l2 == r2
334
- }
335
- ( Self :: Subtype ( l0) , Self :: Subtype ( r0) ) => l0 == r0,
336
- ( Self :: Coerce ( l0) , Self :: Coerce ( r0) ) => l0 == r0,
337
- ( Self :: ConstEquate ( l0, l1) , Self :: ConstEquate ( r0, r1) ) => l0 == r0 && l1 == r1,
338
- ( Self :: AliasRelate ( l0, l1, l2) , Self :: AliasRelate ( r0, r1, r2) ) => {
339
- l0 == r0 && l1 == r1 && l2 == r2
340
- }
341
- _ => core:: mem:: discriminant ( self ) == core:: mem:: discriminant ( other) ,
342
- }
343
- }
344
- }
345
-
346
- impl < I : Interner > Eq for PredicateKind < I > { }
347
-
348
262
fn predicate_kind_discriminant < I : Interner > ( value : & PredicateKind < I > ) -> usize {
349
263
match value {
350
264
PredicateKind :: Clause ( _) => 0 ,
@@ -358,33 +272,6 @@ fn predicate_kind_discriminant<I: Interner>(value: &PredicateKind<I>) -> usize {
358
272
}
359
273
}
360
274
361
- impl < I : Interner > hash:: Hash for PredicateKind < I > {
362
- fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
363
- predicate_kind_discriminant ( self ) . hash ( state) ;
364
- match self {
365
- PredicateKind :: Clause ( p) => p. hash ( state) ,
366
- PredicateKind :: ObjectSafe ( d) => d. hash ( state) ,
367
- PredicateKind :: ClosureKind ( d, g, k) => {
368
- d. hash ( state) ;
369
- g. hash ( state) ;
370
- k. hash ( state) ;
371
- }
372
- PredicateKind :: Subtype ( p) => p. hash ( state) ,
373
- PredicateKind :: Coerce ( p) => p. hash ( state) ,
374
- PredicateKind :: ConstEquate ( c1, c2) => {
375
- c1. hash ( state) ;
376
- c2. hash ( state) ;
377
- }
378
- PredicateKind :: Ambiguous => { }
379
- PredicateKind :: AliasRelate ( t1, t2, r) => {
380
- t1. hash ( state) ;
381
- t2. hash ( state) ;
382
- r. hash ( state) ;
383
- }
384
- }
385
- }
386
- }
387
-
388
275
impl < CTX : HashStableContext , I : Interner > HashStable < CTX > for PredicateKind < I >
389
276
where
390
277
I :: DefId : HashStable < CTX > ,
0 commit comments