File tree Expand file tree Collapse file tree 3 files changed +41
-3
lines changed Expand file tree Collapse file tree 3 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -1413,6 +1413,10 @@ extern "rust-intrinsic" {
1413
1413
/// This is implemented as an intrinsic to avoid converting to and from an
1414
1414
/// integer, since the conversion would throw away aliasing information.
1415
1415
///
1416
+ /// This can only be used with `Ptr` as a raw pointer type (`*mut` or `*const`)
1417
+ /// to a `Sized` pointee and with `Delta` as `usize` or `isize`. Any other
1418
+ /// instantiations may arbitrarily misbehave, and that's *not* a compiler bug.
1419
+ ///
1416
1420
/// # Safety
1417
1421
///
1418
1422
/// Both the starting and resulting pointer must be either in bounds or one
@@ -1421,6 +1425,14 @@ extern "rust-intrinsic" {
1421
1425
/// returned value will result in undefined behavior.
1422
1426
///
1423
1427
/// The stabilized version of this intrinsic is [`pointer::offset`].
1428
+ #[ cfg( not( bootstrap) ) ]
1429
+ #[ must_use = "returns a new pointer rather than modifying its argument" ]
1430
+ #[ rustc_const_stable( feature = "const_ptr_offset" , since = "1.61.0" ) ]
1431
+ #[ rustc_nounwind]
1432
+ pub fn offset < Ptr , Delta > ( dst : Ptr , offset : Delta ) -> Ptr ;
1433
+
1434
+ /// The bootstrap version of this is more restricted.
1435
+ #[ cfg( bootstrap) ]
1424
1436
#[ must_use = "returns a new pointer rather than modifying its argument" ]
1425
1437
#[ rustc_const_stable( feature = "const_ptr_offset" , since = "1.61.0" ) ]
1426
1438
#[ rustc_nounwind]
Original file line number Diff line number Diff line change @@ -916,8 +916,16 @@ impl<T: ?Sized> *const T {
916
916
where
917
917
T : Sized ,
918
918
{
919
+ #[ cfg( bootstrap) ]
919
920
// SAFETY: the caller must uphold the safety contract for `offset`.
920
- unsafe { self . offset ( count as isize ) }
921
+ unsafe {
922
+ self . offset ( count as isize )
923
+ }
924
+ #[ cfg( not( bootstrap) ) ]
925
+ // SAFETY: the caller must uphold the safety contract for `offset`.
926
+ unsafe {
927
+ intrinsics:: offset ( self , count)
928
+ }
921
929
}
922
930
923
931
/// Calculates the offset from a pointer in bytes (convenience for `.byte_offset(count as isize)`).
Original file line number Diff line number Diff line change @@ -473,10 +473,20 @@ impl<T: ?Sized> *mut T {
473
473
where
474
474
T : Sized ,
475
475
{
476
+ #[ cfg( bootstrap) ]
476
477
// SAFETY: the caller must uphold the safety contract for `offset`.
477
478
// The obtained pointer is valid for writes since the caller must
478
479
// guarantee that it points to the same allocated object as `self`.
479
- unsafe { intrinsics:: offset ( self , count) as * mut T }
480
+ unsafe {
481
+ intrinsics:: offset ( self , count) as * mut T
482
+ }
483
+ #[ cfg( not( bootstrap) ) ]
484
+ // SAFETY: the caller must uphold the safety contract for `offset`.
485
+ // The obtained pointer is valid for writes since the caller must
486
+ // guarantee that it points to the same allocated object as `self`.
487
+ unsafe {
488
+ intrinsics:: offset ( self , count)
489
+ }
480
490
}
481
491
482
492
/// Calculates the offset from a pointer in bytes.
@@ -1016,8 +1026,16 @@ impl<T: ?Sized> *mut T {
1016
1026
where
1017
1027
T : Sized ,
1018
1028
{
1029
+ #[ cfg( bootstrap) ]
1030
+ // SAFETY: the caller must uphold the safety contract for `offset`.
1031
+ unsafe {
1032
+ self . offset ( count as isize )
1033
+ }
1034
+ #[ cfg( not( bootstrap) ) ]
1019
1035
// SAFETY: the caller must uphold the safety contract for `offset`.
1020
- unsafe { self . offset ( count as isize ) }
1036
+ unsafe {
1037
+ intrinsics:: offset ( self , count)
1038
+ }
1021
1039
}
1022
1040
1023
1041
/// Calculates the offset from a pointer in bytes (convenience for `.byte_offset(count as isize)`).
You can’t perform that action at this time.
0 commit comments