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