@@ -1907,13 +1907,59 @@ pub enum Place<'tcx> {
19071907}
19081908
19091909/// A new Place repr
1910- #[ derive( Clone , Debug , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable ) ]
1910+ #[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
19111911pub struct NeoPlace < ' tcx > {
19121912 pub base : PlaceBase < ' tcx > ,
1913- pub elems : & ' tcx List < PlaceElem < ' tcx > > ,
1913+ pub elems : & ' tcx [ PlaceElem < ' tcx > ] ,
19141914}
19151915
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 > > ;
19171963
19181964impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' tcx > {
19191965 pub fn as_new_place ( self , place : & Place < ' tcx > ) -> NeoPlace < ' tcx > {
@@ -1977,7 +2023,7 @@ impl_stable_hash_for!(struct Static<'tcx> {
19772023/// or `*B` or `B[index]`. Note that it is parameterized because it is
19782024/// shared between `Constant` and `Place`. See the aliases
19792025/// `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 ) ]
19812027pub struct Projection < ' tcx , B , V , T > {
19822028 pub base : B ,
19832029 pub elem : ProjectionElem < ' tcx , V , T > ,
@@ -3483,7 +3529,7 @@ impl<'tcx> TypeFoldable<'tcx> for PlaceBase<'tcx> {
34833529 }
34843530}
34853531
3486- impl < ' tcx > TypeFoldable < ' tcx > for & ' tcx List < PlaceElem < ' tcx > > {
3532+ impl < ' tcx > TypeFoldable < ' tcx > for & ' tcx [ PlaceElem < ' tcx > ] {
34873533 fn super_fold_with < ' gcx : ' tcx , F : TypeFolder < ' gcx , ' tcx > > ( & self , folder : & mut F ) -> Self {
34883534 let v = self . iter ( ) . map ( |p| p. fold_with ( folder) ) . collect :: < SmallVec < [ _ ; 8 ] > > ( ) ;
34893535 folder. tcx ( ) . intern_place_elems ( & v)
0 commit comments