@@ -288,7 +288,7 @@ impl From<CtfeProvenance> for Pointer {
288288impl < Prov > From < Pointer < Prov > > for Pointer < Option < Prov > > {
289289 #[ inline( always) ]
290290 fn from ( ptr : Pointer < Prov > ) -> Self {
291- let ( prov, offset) = ptr. into_parts ( ) ;
291+ let ( prov, offset) = ptr. into_raw_parts ( ) ;
292292 Pointer :: new ( Some ( prov) , offset)
293293 }
294294}
@@ -314,9 +314,7 @@ impl<Prov> Pointer<Option<Prov>> {
314314 assert ! ( Prov :: OFFSET_IS_ADDR ) ;
315315 self . offset
316316 }
317- }
318317
319- impl < Prov > Pointer < Option < Prov > > {
320318 /// Creates a pointer to the given address, with invalid provenance (i.e., cannot be used for
321319 /// any memory access).
322320 #[ inline( always) ]
@@ -336,11 +334,11 @@ impl<Prov> Pointer<Prov> {
336334 Pointer { provenance, offset }
337335 }
338336
339- /// Obtain the constituents of this pointer. Not that the meaning of the offset depends on the type `Prov`!
340- /// This function must only be used in the implementation of `Machine::ptr_get_alloc`,
341- /// and when a `Pointer` is taken apart to be stored efficiently in an `Allocation` .
337+ /// Obtain the constituents of this pointer. Note that the meaning of the offset depends on the
338+ /// type `Prov`! This is a low-level function that should only be used when absolutely
339+ /// necessary. Prefer `prov_and_relative_offset` if possible .
342340 #[ inline( always) ]
343- pub fn into_parts ( self ) -> ( Prov , Size ) {
341+ pub fn into_raw_parts ( self ) -> ( Prov , Size ) {
344342 ( self . provenance , self . offset )
345343 }
346344
@@ -361,3 +359,12 @@ impl<Prov> Pointer<Prov> {
361359 self . wrapping_offset ( Size :: from_bytes ( i as u64 ) , cx)
362360 }
363361}
362+
363+ impl Pointer < CtfeProvenance > {
364+ /// Return the provenance and relative offset stored in this pointer. Safer alternative to
365+ /// `into_raw_parts` since the type ensures that the offset is indeed relative.
366+ #[ inline( always) ]
367+ pub fn prov_and_relative_offset ( self ) -> ( CtfeProvenance , Size ) {
368+ ( self . provenance , self . offset )
369+ }
370+ }
0 commit comments