1
- use std:: { fmt, marker:: PhantomData } ;
1
+ use std:: {
2
+ fmt,
3
+ hash:: { Hash , Hasher } ,
4
+ marker:: PhantomData ,
5
+ } ;
2
6
3
7
use syntax:: ast;
4
8
@@ -10,14 +14,37 @@ use rustc_hir::{self as hir, def_id::DefId};
10
14
11
15
pub use self :: ViewKind :: * ;
12
16
13
- // TODO Forward eq/hash?
14
- #[ derive( Eq , PartialEq , Hash , TypeFoldable , Lift ) ]
17
+ #[ derive( TypeFoldable , Lift ) ]
15
18
pub struct View < ' tcx , T > {
16
19
ty : Ty < ' tcx > ,
17
20
_marker : PhantomData < T > ,
18
21
}
19
22
23
+ impl < ' tcx , T > PartialEq for View < ' tcx , T >
24
+ where
25
+ T : PartialEq + TyDeref < ' tcx > ,
26
+ {
27
+ fn eq ( & self , other : & Self ) -> bool {
28
+ * * self == * * other
29
+ }
30
+ }
31
+
32
+ impl < ' tcx , T > Eq for View < ' tcx , T > where T : Eq + TyDeref < ' tcx > { }
33
+
34
+ impl < ' tcx , T > Hash for View < ' tcx , T >
35
+ where
36
+ T : Hash + TyDeref < ' tcx > ,
37
+ {
38
+ fn hash < H > ( & self , hasher : & mut H )
39
+ where
40
+ H : Hasher ,
41
+ {
42
+ ( * * self ) . hash ( hasher)
43
+ }
44
+ }
45
+
20
46
impl < T > Copy for View < ' _ , T > { }
47
+
21
48
impl < T > Clone for View < ' _ , T > {
22
49
fn clone ( & self ) -> Self {
23
50
View { ty : self . ty , _marker : PhantomData }
@@ -35,15 +62,15 @@ where
35
62
36
63
impl < ' tcx , T > fmt:: Display for View < ' tcx , T >
37
64
where
38
- T : fmt:: Display + TyDeref < ' tcx > + ' tcx ,
65
+ T : fmt:: Display + TyDeref < ' tcx > ,
39
66
{
40
67
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
41
68
( * * self ) . fmt ( f)
42
69
}
43
70
}
44
71
impl < ' tcx , T > std:: ops:: Deref for View < ' tcx , T >
45
72
where
46
- T : TyDeref < ' tcx > + ' tcx ,
73
+ T : TyDeref < ' tcx > ,
47
74
{
48
75
type Target = T ;
49
76
fn deref ( & self ) -> & Self :: Target {
57
84
58
85
impl < ' tcx , T > View < ' tcx , T >
59
86
where
60
- T : TyDeref < ' tcx > + ' tcx ,
87
+ T : TyDeref < ' tcx > ,
61
88
{
62
89
pub fn new ( ty : Ty < ' tcx > ) -> Option < Self > {
63
90
T :: ty_deref ( ty) ?;
@@ -73,7 +100,7 @@ impl<'tcx, T> View<'tcx, T> {
73
100
74
101
/// SAFETY If `Some` is returned for `ty` then `Some` must always be returned for any subsequent
75
102
/// call with the same `Ty` value
76
- pub unsafe trait TyDeref < ' tcx > : Sized {
103
+ pub unsafe trait TyDeref < ' tcx > : Sized + ' tcx {
77
104
fn ty_deref ( ty : Ty < ' tcx > ) -> Option < & ' tcx Self > ;
78
105
}
79
106
0 commit comments