@@ -4,6 +4,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
4
4
use rustc_data_structures:: unify:: { EqUnifyValue , UnifyKey } ;
5
5
use std:: fmt;
6
6
7
+ use crate :: fold:: { FallibleTypeFolder , TypeFoldable } ;
8
+ use crate :: visit:: { TypeVisitable , TypeVisitor } ;
7
9
use crate :: Interner ;
8
10
use crate :: { DebruijnIndex , DebugWithInfcx , InferCtxtLike , WithInfcx } ;
9
11
@@ -158,7 +160,7 @@ pub enum TyKind<I: Interner> {
158
160
Slice ( I :: Ty ) ,
159
161
160
162
/// A raw pointer. Written as `*mut T` or `*const T`
161
- RawPtr ( I :: TypeAndMut ) ,
163
+ RawPtr ( TypeAndMut < I > ) ,
162
164
163
165
/// A reference; a pointer with an associated lifetime. Written as
164
166
/// `&'a mut T` or `&'a T`.
@@ -410,8 +412,7 @@ impl<I: Interner> DebugWithInfcx<I> for TyKind<I> {
410
412
Str => write ! ( f, "str" ) ,
411
413
Array ( t, c) => write ! ( f, "[{:?}; {:?}]" , & this. wrap( t) , & this. wrap( c) ) ,
412
414
Slice ( t) => write ! ( f, "[{:?}]" , & this. wrap( t) ) ,
413
- RawPtr ( p) => {
414
- let ( ty, mutbl) = I :: ty_and_mut_to_parts ( * p) ;
415
+ RawPtr ( TypeAndMut { ty, mutbl } ) => {
415
416
match mutbl {
416
417
Mutability :: Mut => write ! ( f, "*mut " ) ,
417
418
Mutability :: Not => write ! ( f, "*const " ) ,
@@ -831,3 +832,42 @@ impl<I: Interner> DebugWithInfcx<I> for InferTy {
831
832
}
832
833
}
833
834
}
835
+
836
+ #[ derive( derivative:: Derivative ) ]
837
+ #[ derivative(
838
+ Clone ( bound = "" ) ,
839
+ Copy ( bound = "" ) ,
840
+ PartialOrd ( bound = "" ) ,
841
+ Ord ( bound = "" ) ,
842
+ PartialEq ( bound = "" ) ,
843
+ Eq ( bound = "" ) ,
844
+ Hash ( bound = "" ) ,
845
+ Debug ( bound = "" )
846
+ ) ]
847
+ #[ cfg_attr( feature = "nightly" , derive( TyEncodable , TyDecodable , HashStable_NoContext ) ) ]
848
+ pub struct TypeAndMut < I : Interner > {
849
+ pub ty : I :: Ty ,
850
+ pub mutbl : Mutability ,
851
+ }
852
+
853
+ impl < I : Interner > TypeFoldable < I > for TypeAndMut < I >
854
+ where
855
+ I :: Ty : TypeFoldable < I > ,
856
+ {
857
+ fn try_fold_with < F : FallibleTypeFolder < I > > ( self , folder : & mut F ) -> Result < Self , F :: Error > {
858
+ Ok ( TypeAndMut {
859
+ ty : self . ty . try_fold_with ( folder) ?,
860
+ mutbl : self . mutbl . try_fold_with ( folder) ?,
861
+ } )
862
+ }
863
+ }
864
+
865
+ impl < I : Interner > TypeVisitable < I > for TypeAndMut < I >
866
+ where
867
+ I :: Ty : TypeVisitable < I > ,
868
+ {
869
+ fn visit_with < V : TypeVisitor < I > > ( & self , visitor : & mut V ) -> std:: ops:: ControlFlow < V :: BreakTy > {
870
+ self . ty . visit_with ( visitor) ?;
871
+ self . mutbl . visit_with ( visitor)
872
+ }
873
+ }
0 commit comments