@@ -963,7 +963,7 @@ pub enum PointerCoercion {
963963 /// Go from a safe fn pointer to an unsafe fn pointer.
964964 UnsafeFnPointer ,
965965
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.
967967 /// It cannot convert a closure that requires unsafe.
968968 ClosureFnPointer ( Safety ) ,
969969
@@ -1037,21 +1037,24 @@ impl Place {
10371037 /// locals from the function body where this place originates from.
10381038 pub fn ty ( & self , locals : & [ LocalDecl ] ) -> Result < Ty , Error > {
10391039 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)
10531054 }
1054- } )
1055+ ProjectionElem :: Downcast ( _) => Ok ( ty) ,
1056+ ProjectionElem :: OpaqueCast ( ty) | ProjectionElem :: Subtype ( ty) => Ok ( * ty) ,
1057+ }
10551058 }
10561059
10571060 fn index_ty ( ty : Ty ) -> Result < Ty , Error > {
0 commit comments