@@ -288,7 +288,7 @@ impl From<CtfeProvenance> for Pointer {
288
288
impl < Prov > From < Pointer < Prov > > for Pointer < Option < Prov > > {
289
289
#[ inline( always) ]
290
290
fn from ( ptr : Pointer < Prov > ) -> Self {
291
- let ( prov, offset) = ptr. into_parts ( ) ;
291
+ let ( prov, offset) = ptr. into_raw_parts ( ) ;
292
292
Pointer :: new ( Some ( prov) , offset)
293
293
}
294
294
}
@@ -314,9 +314,7 @@ impl<Prov> Pointer<Option<Prov>> {
314
314
assert ! ( Prov :: OFFSET_IS_ADDR ) ;
315
315
self . offset
316
316
}
317
- }
318
317
319
- impl < Prov > Pointer < Option < Prov > > {
320
318
/// Creates a pointer to the given address, with invalid provenance (i.e., cannot be used for
321
319
/// any memory access).
322
320
#[ inline( always) ]
@@ -336,11 +334,11 @@ impl<Prov> Pointer<Prov> {
336
334
Pointer { provenance, offset }
337
335
}
338
336
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 .
342
340
#[ inline( always) ]
343
- pub fn into_parts ( self ) -> ( Prov , Size ) {
341
+ pub fn into_raw_parts ( self ) -> ( Prov , Size ) {
344
342
( self . provenance , self . offset )
345
343
}
346
344
@@ -361,3 +359,12 @@ impl<Prov> Pointer<Prov> {
361
359
self . wrapping_offset ( Size :: from_bytes ( i as u64 ) , cx)
362
360
}
363
361
}
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