@@ -64,6 +64,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
6464                self . write_immediate ( * res,  dest) ?; 
6565            } 
6666
67+             CastKind :: PtrToMetadata  => { 
68+                 let  src = self . read_immediate ( src) ?; 
69+                 let  res = self . ptr_to_metadata ( & src,  cast_layout) ?; 
70+                 self . write_immediate ( * res,  dest) ?; 
71+             } 
72+ 
6773            CastKind :: PointerCoercion ( 
6874                PointerCoercion :: MutToConstPointer  | PointerCoercion :: ArrayToPointer , 
6975            )  => { 
@@ -204,7 +210,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
204210        assert ! ( cast_to. ty. is_unsafe_ptr( ) ) ; 
205211        // Handle casting any ptr to raw ptr (might be a fat ptr). 
206212        if  cast_to. size  == src. layout . size  { 
207-             // Thin or fat pointer that just hast  the ptr kind of target type changed. 
213+             // Thin or fat pointer that just has  the ptr kind of target type changed. 
208214            return  Ok ( ImmTy :: from_immediate ( * * src,  cast_to) ) ; 
209215        }  else  { 
210216            // Casting the metadata away from a fat ptr. 
@@ -225,6 +231,22 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
225231        } 
226232    } 
227233
234+     fn  ptr_to_metadata ( 
235+         & self , 
236+         src :  & ImmTy < ' tcx ,  M :: Provenance > , 
237+         cast_to :  TyAndLayout < ' tcx > , 
238+     )  -> InterpResult < ' tcx ,  ImmTy < ' tcx ,  M :: Provenance > >  { 
239+         assert ! ( src. layout. ty. is_unsafe_ptr( ) ) ; 
240+         return  Ok ( match  * * src { 
241+             Immediate :: Scalar ( _)  => { 
242+                 assert ! ( cast_to. is_zst( ) ) ; 
243+                 ImmTy :: uninit ( cast_to) 
244+             } 
245+             Immediate :: ScalarPair ( _,  meta)  => ImmTy :: from_scalar ( meta,  cast_to) , 
246+             Immediate :: Uninit  => throw_ub ! ( InvalidUninitBytes ( None ) ) , 
247+         } ) ; 
248+     } 
249+ 
228250    pub  fn  pointer_expose_provenance_cast ( 
229251        & mut  self , 
230252        src :  & ImmTy < ' tcx ,  M :: Provenance > , 
0 commit comments