@@ -4,6 +4,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
44use rustc_data_structures:: unify:: { EqUnifyValue , UnifyKey } ;
55use std:: fmt;
66
7+ use crate :: fold:: { FallibleTypeFolder , TypeFoldable } ;
8+ use crate :: visit:: { TypeVisitable , TypeVisitor } ;
79use crate :: Interner ;
810use crate :: { DebruijnIndex , DebugWithInfcx , InferCtxtLike , WithInfcx } ;
911
@@ -158,7 +160,7 @@ pub enum TyKind<I: Interner> {
158160 Slice ( I :: Ty ) ,
159161
160162 /// A raw pointer. Written as `*mut T` or `*const T`
161- RawPtr ( I :: TypeAndMut ) ,
163+ RawPtr ( TypeAndMut < I > ) ,
162164
163165 /// A reference; a pointer with an associated lifetime. Written as
164166 /// `&'a mut T` or `&'a T`.
@@ -410,8 +412,7 @@ impl<I: Interner> DebugWithInfcx<I> for TyKind<I> {
410412 Str => write ! ( f, "str" ) ,
411413 Array ( t, c) => write ! ( f, "[{:?}; {:?}]" , & this. wrap( t) , & this. wrap( c) ) ,
412414 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 } ) => {
415416 match mutbl {
416417 Mutability :: Mut => write ! ( f, "*mut " ) ,
417418 Mutability :: Not => write ! ( f, "*const " ) ,
@@ -831,3 +832,42 @@ impl<I: Interner> DebugWithInfcx<I> for InferTy {
831832 }
832833 }
833834}
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