@@ -1907,14 +1907,47 @@ pub enum Place<'tcx> {
1907
1907
}
1908
1908
1909
1909
/// A new Place repr
1910
- #[ derive( Clone , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable ) ]
1910
+ #[ derive( Clone , Debug , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable ) ]
1911
1911
pub struct NeoPlace < ' tcx > {
1912
1912
base : PlaceBase < ' tcx > ,
1913
1913
elems : & ' tcx List < PlaceElem < ' tcx > > ,
1914
1914
}
1915
1915
1916
1916
impl < ' tcx > serialize:: UseSpecializedDecodable for & ' tcx List < PlaceElem < ' tcx > > { }
1917
1917
1918
+ impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' tcx > {
1919
+ pub fn as_new_place ( self , place : & Place < ' tcx > ) -> NeoPlace < ' tcx > {
1920
+ let mut elems: Vec < PlaceElem < ' tcx > > = Vec :: new ( ) ;
1921
+ let mut p = place;
1922
+
1923
+ while let Place :: Projection ( proj) = p {
1924
+ elems. push ( proj. elem ) ;
1925
+ p = & proj. base ;
1926
+ }
1927
+
1928
+ elems. reverse ( ) ;
1929
+
1930
+ match p. clone ( ) {
1931
+ Place :: Projection ( _) => unreachable ! ( ) ,
1932
+
1933
+ Place :: Local ( local) => NeoPlace {
1934
+ base : PlaceBase :: Local ( local) ,
1935
+ elems : self . mk_place_elems ( elems. iter ( ) ) ,
1936
+ } ,
1937
+
1938
+ Place :: Static ( static_) => NeoPlace {
1939
+ base : PlaceBase :: Static ( static_) ,
1940
+ elems : self . mk_place_elems ( elems. iter ( ) ) ,
1941
+ } ,
1942
+
1943
+ Place :: Promoted ( promoted) => NeoPlace {
1944
+ base : PlaceBase :: Promoted ( promoted) ,
1945
+ elems : self . mk_place_elems ( elems. iter ( ) ) ,
1946
+ } ,
1947
+ }
1948
+ }
1949
+ }
1950
+
1918
1951
#[ derive( Clone , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable ) ]
1919
1952
pub enum PlaceBase < ' tcx > {
1920
1953
/// local variable
@@ -1950,7 +1983,7 @@ pub struct Projection<'tcx, B, V, T> {
1950
1983
pub elem : ProjectionElem < ' tcx , V , T > ,
1951
1984
}
1952
1985
1953
- #[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash , RustcEncodable , RustcDecodable ) ]
1986
+ #[ derive( Clone , Copy , Debug , PartialEq , Eq , PartialOrd , Ord , Hash , RustcEncodable , RustcDecodable ) ]
1954
1987
pub enum ProjectionElem < ' tcx , V , T > {
1955
1988
Deref ,
1956
1989
Field ( Field , T ) ,
@@ -2103,6 +2136,23 @@ impl<'tcx> Debug for Place<'tcx> {
2103
2136
}
2104
2137
}
2105
2138
2139
+ impl < ' tcx > Debug for PlaceBase < ' tcx > {
2140
+ fn fmt ( & self , fmt : & mut Formatter ) -> fmt:: Result {
2141
+ use self :: PlaceBase :: * ;
2142
+
2143
+ match self {
2144
+ Local ( id) => write ! ( fmt, "{:?}" , * id) ,
2145
+ Static ( box self :: Static { def_id, ty } ) => write ! (
2146
+ fmt,
2147
+ "({}: {:?})" ,
2148
+ ty:: tls:: with( |tcx| tcx. item_path_str( * def_id) ) ,
2149
+ ty
2150
+ ) ,
2151
+ Promoted ( promoted) => write ! ( fmt, "({:?}: {:?})" , promoted. 0 , promoted. 1 ) ,
2152
+ }
2153
+ }
2154
+ }
2155
+
2106
2156
///////////////////////////////////////////////////////////////////////////
2107
2157
// Scopes
2108
2158
@@ -3324,6 +3374,41 @@ impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
3324
3374
}
3325
3375
}
3326
3376
3377
+ impl < ' tcx > TypeFoldable < ' tcx > for NeoPlace < ' tcx > {
3378
+ fn super_fold_with < ' gcx : ' tcx , F : TypeFolder < ' gcx , ' tcx > > ( & self , folder : & mut F ) -> Self {
3379
+ NeoPlace {
3380
+ base : self . base . fold_with ( folder) ,
3381
+ elems : self . elems . fold_with ( folder) ,
3382
+ }
3383
+ }
3384
+
3385
+ fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
3386
+ self . base . visit_with ( visitor) ||
3387
+ self . elems . visit_with ( visitor)
3388
+ }
3389
+ }
3390
+
3391
+ impl < ' tcx > TypeFoldable < ' tcx > for PlaceBase < ' tcx > {
3392
+ fn super_fold_with < ' gcx : ' tcx , F : TypeFolder < ' gcx , ' tcx > > ( & self , _folder : & mut F ) -> Self {
3393
+ self . clone ( )
3394
+ }
3395
+
3396
+ fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , _visitor : & mut V ) -> bool {
3397
+ false
3398
+ }
3399
+ }
3400
+
3401
+ impl < ' tcx > TypeFoldable < ' tcx > for & ' tcx List < PlaceElem < ' tcx > > {
3402
+ fn super_fold_with < ' gcx : ' tcx , F : TypeFolder < ' gcx , ' tcx > > ( & self , folder : & mut F ) -> Self {
3403
+ let v = self . iter ( ) . map ( |p| p. fold_with ( folder) ) . collect :: < SmallVec < [ _ ; 8 ] > > ( ) ;
3404
+ folder. tcx ( ) . intern_place_elems ( & v)
3405
+ }
3406
+
3407
+ fn super_visit_with < Vs : TypeVisitor < ' tcx > > ( & self , visitor : & mut Vs ) -> bool {
3408
+ self . iter ( ) . any ( |p| p. visit_with ( visitor) )
3409
+ }
3410
+ }
3411
+
3327
3412
impl < ' tcx > TypeFoldable < ' tcx > for Rvalue < ' tcx > {
3328
3413
fn super_fold_with < ' gcx : ' tcx , F : TypeFolder < ' gcx , ' tcx > > ( & self , folder : & mut F ) -> Self {
3329
3414
use mir:: Rvalue :: * ;
@@ -3444,6 +3529,31 @@ where
3444
3529
}
3445
3530
}
3446
3531
3532
+ impl < ' tcx , V , T > TypeFoldable < ' tcx > for ProjectionElem < ' tcx , V , T >
3533
+ where
3534
+ V : TypeFoldable < ' tcx > ,
3535
+ T : TypeFoldable < ' tcx > ,
3536
+ {
3537
+ fn super_fold_with < ' gcx : ' tcx , F : TypeFolder < ' gcx , ' tcx > > ( & self , folder : & mut F ) -> Self {
3538
+ use self :: ProjectionElem :: * ;
3539
+ match self {
3540
+ Deref => Deref ,
3541
+ Field ( f, ty) => Field ( * f, ty. fold_with ( folder) ) ,
3542
+ Index ( v) => Index ( v. fold_with ( folder) ) ,
3543
+ elem => elem. clone ( ) ,
3544
+ }
3545
+ }
3546
+
3547
+ fn super_visit_with < Vs : TypeVisitor < ' tcx > > ( & self , visitor : & mut Vs ) -> bool {
3548
+ use self :: ProjectionElem :: * ;
3549
+ match self {
3550
+ Field ( _, ty) => ty. visit_with ( visitor) ,
3551
+ Index ( v) => v. visit_with ( visitor) ,
3552
+ _ => false ,
3553
+ }
3554
+ }
3555
+ }
3556
+
3447
3557
impl < ' tcx > TypeFoldable < ' tcx > for Field {
3448
3558
fn super_fold_with < ' gcx : ' tcx , F : TypeFolder < ' gcx , ' tcx > > ( & self , _: & mut F ) -> Self {
3449
3559
* self
0 commit comments