1- use std:: { fmt, marker:: PhantomData } ;
1+ use std:: {
2+ fmt,
3+ hash:: { Hash , Hasher } ,
4+ marker:: PhantomData ,
5+ } ;
26
37use syntax:: ast;
48
@@ -10,14 +14,37 @@ use rustc_hir::{self as hir, def_id::DefId};
1014
1115pub use self :: ViewKind :: * ;
1216
13- // TODO Forward eq/hash?
14- #[ derive( Eq , PartialEq , Hash , TypeFoldable , Lift ) ]
17+ #[ derive( TypeFoldable , Lift ) ]
1518pub struct View < ' tcx , T > {
1619 ty : Ty < ' tcx > ,
1720 _marker : PhantomData < T > ,
1821}
1922
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+
2046impl < T > Copy for View < ' _ , T > { }
47+
2148impl < T > Clone for View < ' _ , T > {
2249 fn clone ( & self ) -> Self {
2350 View { ty : self . ty , _marker : PhantomData }
@@ -35,15 +62,15 @@ where
3562
3663impl < ' tcx , T > fmt:: Display for View < ' tcx , T >
3764where
38- T : fmt:: Display + TyDeref < ' tcx > + ' tcx ,
65+ T : fmt:: Display + TyDeref < ' tcx > ,
3966{
4067 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
4168 ( * * self ) . fmt ( f)
4269 }
4370}
4471impl < ' tcx , T > std:: ops:: Deref for View < ' tcx , T >
4572where
46- T : TyDeref < ' tcx > + ' tcx ,
73+ T : TyDeref < ' tcx > ,
4774{
4875 type Target = T ;
4976 fn deref ( & self ) -> & Self :: Target {
5784
5885impl < ' tcx , T > View < ' tcx , T >
5986where
60- T : TyDeref < ' tcx > + ' tcx ,
87+ T : TyDeref < ' tcx > ,
6188{
6289 pub fn new ( ty : Ty < ' tcx > ) -> Option < Self > {
6390 T :: ty_deref ( ty) ?;
@@ -73,7 +100,7 @@ impl<'tcx, T> View<'tcx, T> {
73100
74101/// SAFETY If `Some` is returned for `ty` then `Some` must always be returned for any subsequent
75102/// call with the same `Ty` value
76- pub unsafe trait TyDeref < ' tcx > : Sized {
103+ pub unsafe trait TyDeref < ' tcx > : Sized + ' tcx {
77104 fn ty_deref ( ty : Ty < ' tcx > ) -> Option < & ' tcx Self > ;
78105}
79106
0 commit comments