@@ -963,7 +963,7 @@ pub enum PointerCoercion {
963
963
/// Go from a safe fn pointer to an unsafe fn pointer.
964
964
UnsafeFnPointer ,
965
965
966
- /// Go from a non-capturing closure to an fn pointer or an unsafe fn pointer.
966
+ /// Go from a non-capturing closure to a fn pointer or an unsafe fn pointer.
967
967
/// It cannot convert a closure that requires unsafe.
968
968
ClosureFnPointer ( Safety ) ,
969
969
@@ -1037,21 +1037,24 @@ impl Place {
1037
1037
/// locals from the function body where this place originates from.
1038
1038
pub fn ty ( & self , locals : & [ LocalDecl ] ) -> Result < Ty , Error > {
1039
1039
let start_ty = locals[ self . local ] . ty ;
1040
- self . projection . iter ( ) . fold ( Ok ( start_ty) , |place_ty, elem| {
1041
- let ty = place_ty?;
1042
- match elem {
1043
- ProjectionElem :: Deref => Self :: deref_ty ( ty) ,
1044
- ProjectionElem :: Field ( _idx, fty) => Ok ( * fty) ,
1045
- ProjectionElem :: Index ( _) | ProjectionElem :: ConstantIndex { .. } => {
1046
- Self :: index_ty ( ty)
1047
- }
1048
- ProjectionElem :: Subslice { from, to, from_end } => {
1049
- Self :: subslice_ty ( ty, from, to, from_end)
1050
- }
1051
- ProjectionElem :: Downcast ( _) => Ok ( ty) ,
1052
- ProjectionElem :: OpaqueCast ( ty) | ProjectionElem :: Subtype ( ty) => Ok ( * ty) ,
1040
+ self . projection . iter ( ) . fold ( Ok ( start_ty) , |place_ty, elem| elem. ty ( place_ty?) )
1041
+ }
1042
+ }
1043
+
1044
+ impl ProjectionElem {
1045
+ /// Get the expected type after applying this projection to a given place type.
1046
+ pub fn ty ( & self , place_ty : Ty ) -> Result < Ty , Error > {
1047
+ let ty = place_ty;
1048
+ match & self {
1049
+ ProjectionElem :: Deref => Self :: deref_ty ( ty) ,
1050
+ ProjectionElem :: Field ( _idx, fty) => Ok ( * fty) ,
1051
+ ProjectionElem :: Index ( _) | ProjectionElem :: ConstantIndex { .. } => Self :: index_ty ( ty) ,
1052
+ ProjectionElem :: Subslice { from, to, from_end } => {
1053
+ Self :: subslice_ty ( ty, from, to, from_end)
1053
1054
}
1054
- } )
1055
+ ProjectionElem :: Downcast ( _) => Ok ( ty) ,
1056
+ ProjectionElem :: OpaqueCast ( ty) | ProjectionElem :: Subtype ( ty) => Ok ( * ty) ,
1057
+ }
1055
1058
}
1056
1059
1057
1060
fn index_ty ( ty : Ty ) -> Result < Ty , Error > {
0 commit comments