@@ -1896,6 +1896,14 @@ impl<'tcx> Debug for Statement<'tcx> {
18961896/// changing or disturbing program state.
18971897#[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , RustcEncodable , RustcDecodable ) ]
18981898pub enum Place < ' tcx > {
1899+ Base ( PlaceBase < ' tcx > ) ,
1900+
1901+ /// projection out of a place (access a field, deref a pointer, etc)
1902+ Projection ( Box < PlaceProjection < ' tcx > > ) ,
1903+ }
1904+
1905+ #[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , RustcEncodable , RustcDecodable ) ]
1906+ pub enum PlaceBase < ' tcx > {
18991907 /// local variable
19001908 Local ( Local ) ,
19011909
@@ -1904,9 +1912,6 @@ pub enum Place<'tcx> {
19041912
19051913 /// Constant code promoted to an injected static
19061914 Promoted ( Box < ( Promoted , Ty < ' tcx > ) > ) ,
1907-
1908- /// projection out of a place (access a field, deref a pointer, etc)
1909- Projection ( Box < PlaceProjection < ' tcx > > ) ,
19101915}
19111916
19121917/// The `DefId` of a static, along with its normalized type (which is
@@ -1994,6 +1999,8 @@ newtype_index! {
19941999}
19952000
19962001impl < ' tcx > Place < ' tcx > {
2002+ pub const RETURN_PLACE : Place < ' tcx > = Place :: Base ( PlaceBase :: Local ( RETURN_PLACE ) ) ;
2003+
19972004 pub fn field ( self , f : Field , ty : Ty < ' tcx > ) -> Place < ' tcx > {
19982005 self . elem ( ProjectionElem :: Field ( f, ty) )
19992006 }
@@ -2020,9 +2027,9 @@ impl<'tcx> Place<'tcx> {
20202027 // FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
20212028 pub fn local ( & self ) -> Option < Local > {
20222029 match self {
2023- Place :: Local ( local) |
2030+ Place :: Base ( PlaceBase :: Local ( local) ) |
20242031 Place :: Projection ( box Projection {
2025- base : Place :: Local ( local) ,
2032+ base : Place :: Base ( PlaceBase :: Local ( local) ) ,
20262033 elem : ProjectionElem :: Deref ,
20272034 } ) => Some ( * local) ,
20282035 _ => None ,
@@ -2032,9 +2039,9 @@ impl<'tcx> Place<'tcx> {
20322039 /// Finds the innermost `Local` from this `Place`.
20332040 pub fn base_local ( & self ) -> Option < Local > {
20342041 match self {
2035- Place :: Local ( local) => Some ( * local) ,
2042+ Place :: Base ( PlaceBase :: Local ( local) ) => Some ( * local) ,
20362043 Place :: Projection ( box Projection { base, elem : _ } ) => base. base_local ( ) ,
2037- Place :: Promoted ( ..) | Place :: Static ( ..) => None ,
2044+ Place :: Base ( PlaceBase :: Promoted ( ..) ) | Place :: Base ( PlaceBase :: Static ( ..) ) => None ,
20382045 }
20392046 }
20402047}
@@ -2044,14 +2051,19 @@ impl<'tcx> Debug for Place<'tcx> {
20442051 use self :: Place :: * ;
20452052
20462053 match * self {
2047- Local ( id) => write ! ( fmt, "{:?}" , id) ,
2048- Static ( box self :: Static { def_id, ty } ) => write ! (
2054+ Base ( PlaceBase :: Local ( id) ) => write ! ( fmt, "{:?}" , id) ,
2055+ Base ( PlaceBase :: Static ( box self :: Static { def_id, ty } ) ) => write ! (
20492056 fmt,
20502057 "({}: {:?})" ,
20512058 ty:: tls:: with( |tcx| tcx. item_path_str( def_id) ) ,
20522059 ty
20532060 ) ,
2054- Promoted ( ref promoted) => write ! ( fmt, "({:?}: {:?})" , promoted. 0 , promoted. 1 ) ,
2061+ Base ( PlaceBase :: Promoted ( ref promoted) ) => write ! (
2062+ fmt,
2063+ "({:?}: {:?})" ,
2064+ promoted. 0 ,
2065+ promoted. 1
2066+ ) ,
20552067 Projection ( ref data) => match data. elem {
20562068 ProjectionElem :: Downcast ( ref adt_def, index) => {
20572069 write ! ( fmt, "({:?} as {})" , data. base, adt_def. variants[ index] . ident)
0 commit comments