@@ -890,11 +890,18 @@ pub struct Place<'tcx> {
890
890
pub projection : & ' tcx List < PlaceElem < ' tcx > > ,
891
891
}
892
892
893
+ /// The different kinds of projections that can be used in the projection of a `Place`.
894
+ ///
895
+ /// `T1` is the generic type for a field projection. For an actual projection on a `Place`
896
+ /// this parameter will always be `Ty`, but the field type can be unavailable when
897
+ /// building (by using `PlaceBuilder`) places that correspond to upvars.
898
+ /// `T2` is the generic type for an `OpaqueCast` (is generic since it's abstracted over
899
+ /// in dataflow analysis, see `AbstractElem`).
893
900
#[ derive( Copy , Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
894
901
#[ derive( TyEncodable , TyDecodable , HashStable , TypeFoldable , TypeVisitable ) ]
895
- pub enum ProjectionElem < V , T > {
902
+ pub enum ProjectionElem < V , T1 , T2 > {
896
903
Deref ,
897
- Field ( Field , T ) ,
904
+ Field ( Field , T1 ) ,
898
905
/// Index into a slice/array.
899
906
///
900
907
/// Note that this does not also dereference, and so it does not exactly correspond to slice
@@ -950,12 +957,36 @@ pub enum ProjectionElem<V, T> {
950
957
951
958
/// Like an explicit cast from an opaque type to a concrete type, but without
952
959
/// requiring an intermediate variable.
953
- OpaqueCast ( T ) ,
960
+ OpaqueCast ( T2 ) ,
954
961
}
955
962
956
963
/// Alias for projections as they appear in places, where the base is a place
957
964
/// and the index is a local.
958
- pub type PlaceElem < ' tcx > = ProjectionElem < Local , Ty < ' tcx > > ;
965
+ pub type PlaceElem < ' tcx > = ProjectionElem < Local , Ty < ' tcx > , Ty < ' tcx > > ;
966
+
967
+ /// Alias for projections that appear in `PlaceBuilder::Upvar`, for which
968
+ /// we cannot provide any field types.
969
+ pub type UpvarProjectionElem < ' tcx > = ProjectionElem < Local , ( ) , Ty < ' tcx > > ;
970
+
971
+ impl < ' tcx > From < PlaceElem < ' tcx > > for UpvarProjectionElem < ' tcx > {
972
+ fn from ( elem : PlaceElem < ' tcx > ) -> Self {
973
+ match elem {
974
+ ProjectionElem :: Deref => ProjectionElem :: Deref ,
975
+ ProjectionElem :: Field ( field, _) => ProjectionElem :: Field ( field, ( ) ) ,
976
+ ProjectionElem :: Index ( v) => ProjectionElem :: Index ( v) ,
977
+ ProjectionElem :: ConstantIndex { offset, min_length, from_end } => {
978
+ ProjectionElem :: ConstantIndex { offset, min_length, from_end }
979
+ }
980
+ ProjectionElem :: Subslice { from, to, from_end } => {
981
+ ProjectionElem :: Subslice { from, to, from_end }
982
+ }
983
+ ProjectionElem :: Downcast ( opt_sym, variant_idx) => {
984
+ ProjectionElem :: Downcast ( opt_sym, variant_idx)
985
+ }
986
+ ProjectionElem :: OpaqueCast ( ty) => ProjectionElem :: OpaqueCast ( ty) ,
987
+ }
988
+ }
989
+ }
959
990
960
991
///////////////////////////////////////////////////////////////////////////
961
992
// Operands
0 commit comments