@@ -1907,13 +1907,59 @@ pub enum Place<'tcx> {
1907
1907
}
1908
1908
1909
1909
/// A new Place repr
1910
- #[ derive( Clone , Debug , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable ) ]
1910
+ #[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
1911
1911
pub struct NeoPlace < ' tcx > {
1912
1912
pub base : PlaceBase < ' tcx > ,
1913
- pub elems : & ' tcx List < PlaceElem < ' tcx > > ,
1913
+ pub elems : & ' tcx [ PlaceElem < ' tcx > ] ,
1914
1914
}
1915
1915
1916
- impl < ' tcx > serialize:: UseSpecializedDecodable for & ' tcx List < PlaceElem < ' tcx > > { }
1916
+ // FIXME
1917
+ // impl<'tcx> serialize::UseSpecializedDecodable for &'tcx List<PlaceElem<'tcx>> {}
1918
+
1919
+ impl NeoPlace < ' tcx > {
1920
+ /// Return `Some` if this place has no projections -- else return `None`.
1921
+ /// So for `a` would return `Some`, but for `a.b.c` would return `None`.
1922
+ pub fn as_base ( & self ) -> Option < & PlaceBase < ' tcx > > {
1923
+ if !self . elems . is_empty ( ) {
1924
+ // this is something like `a.b.c`
1925
+ return None ;
1926
+ }
1927
+
1928
+ Some ( & self . base )
1929
+ }
1930
+
1931
+ /// Return `Some` if this is just a reference to a local variable
1932
+ /// (e.g., `a`) and `None` if it is something else (e.g.,
1933
+ /// `a.b.c`).
1934
+ pub fn as_local ( & self ) -> Option < Local > {
1935
+ match self . as_base ( ) ? {
1936
+ PlaceBase :: Local ( l) => Some ( * l) ,
1937
+ _ => None ,
1938
+ }
1939
+ }
1940
+
1941
+ pub fn into_tree ( self ) -> NeoPlaceTree < ' tcx > {
1942
+ match self . elems . split_last ( ) {
1943
+ None => NeoPlaceTree :: Base ( self . base ) ,
1944
+ Some ( ( last_element, other_elements) ) => {
1945
+ NeoPlaceTree :: Projected ( Projection {
1946
+ base : NeoPlace { base : self . base , elems : other_elements } ,
1947
+ elem : * last_element,
1948
+ } )
1949
+ }
1950
+ }
1951
+ }
1952
+ }
1953
+
1954
+ #[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
1955
+ pub enum NeoPlaceTree < ' tcx > {
1956
+ Base ( PlaceBase < ' tcx > ) ,
1957
+ Projected ( NeoPlaceProjection < ' tcx > ) ,
1958
+ }
1959
+
1960
+ /// Alias for projections as they appear in places, where the base is a place
1961
+ /// and the index is a local.
1962
+ pub type NeoPlaceProjection < ' tcx > = Projection < ' tcx , NeoPlace < ' tcx > , Local , Ty < ' tcx > > ;
1917
1963
1918
1964
impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' tcx > {
1919
1965
pub fn as_new_place ( self , place : & Place < ' tcx > ) -> NeoPlace < ' tcx > {
@@ -1977,7 +2023,7 @@ impl_stable_hash_for!(struct Static<'tcx> {
1977
2023
/// or `*B` or `B[index]`. Note that it is parameterized because it is
1978
2024
/// shared between `Constant` and `Place`. See the aliases
1979
2025
/// `PlaceProjection` etc below.
1980
- #[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash , RustcEncodable , RustcDecodable ) ]
2026
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash , RustcEncodable , RustcDecodable ) ]
1981
2027
pub struct Projection < ' tcx , B , V , T > {
1982
2028
pub base : B ,
1983
2029
pub elem : ProjectionElem < ' tcx , V , T > ,
@@ -3483,7 +3529,7 @@ impl<'tcx> TypeFoldable<'tcx> for PlaceBase<'tcx> {
3483
3529
}
3484
3530
}
3485
3531
3486
- impl < ' tcx > TypeFoldable < ' tcx > for & ' tcx List < PlaceElem < ' tcx > > {
3532
+ impl < ' tcx > TypeFoldable < ' tcx > for & ' tcx [ PlaceElem < ' tcx > ] {
3487
3533
fn super_fold_with < ' gcx : ' tcx , F : TypeFolder < ' gcx , ' tcx > > ( & self , folder : & mut F ) -> Self {
3488
3534
let v = self . iter ( ) . map ( |p| p. fold_with ( folder) ) . collect :: < SmallVec < [ _ ; 8 ] > > ( ) ;
3489
3535
folder. tcx ( ) . intern_place_elems ( & v)
0 commit comments