@@ -160,7 +160,11 @@ impl<'tcx> PlaceTy<'tcx> {
160160 /// Convenience wrapper around `projection_ty_core` for `PlaceElem`,
161161 /// where we can just use the `Ty` that is already stored inline on
162162 /// field projection elems.
163- pub fn projection_ty ( self , tcx : TyCtxt < ' tcx > , elem : PlaceElem < ' tcx > ) -> PlaceTy < ' tcx > {
163+ pub fn projection_ty < V : :: std:: fmt:: Debug > (
164+ self ,
165+ tcx : TyCtxt < ' tcx > ,
166+ elem : ProjectionElem < V , Ty < ' tcx > > ,
167+ ) -> PlaceTy < ' tcx > {
164168 self . projection_ty_core ( tcx, & elem, |ty| ty, |_, _, _, ty| ty, |ty| ty)
165169 }
166170
@@ -290,6 +294,30 @@ impl<V, T> ProjectionElem<V, T> {
290294 Self :: UnwrapUnsafeBinder ( ..) => false ,
291295 }
292296 }
297+
298+ pub fn try_map < V2 , T2 > (
299+ self ,
300+ v : impl FnOnce ( V ) -> Option < V2 > ,
301+ t : impl FnOnce ( T ) -> T2 ,
302+ ) -> Option < ProjectionElem < V2 , T2 > > {
303+ Some ( match self {
304+ ProjectionElem :: Deref => ProjectionElem :: Deref ,
305+ ProjectionElem :: Downcast ( name, read_variant) => {
306+ ProjectionElem :: Downcast ( name, read_variant)
307+ }
308+ ProjectionElem :: Field ( f, ty) => ProjectionElem :: Field ( f, t ( ty) ) ,
309+ ProjectionElem :: ConstantIndex { offset, min_length, from_end } => {
310+ ProjectionElem :: ConstantIndex { offset, min_length, from_end }
311+ }
312+ ProjectionElem :: Subslice { from, to, from_end } => {
313+ ProjectionElem :: Subslice { from, to, from_end }
314+ }
315+ ProjectionElem :: OpaqueCast ( ty) => ProjectionElem :: OpaqueCast ( t ( ty) ) ,
316+ ProjectionElem :: Subtype ( ty) => ProjectionElem :: Subtype ( t ( ty) ) ,
317+ ProjectionElem :: UnwrapUnsafeBinder ( ty) => ProjectionElem :: UnwrapUnsafeBinder ( t ( ty) ) ,
318+ ProjectionElem :: Index ( val) => ProjectionElem :: Index ( v ( val) ?) ,
319+ } )
320+ }
293321}
294322
295323/// Alias for projections as they appear in `UserTypeProjection`, where we
0 commit comments