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" {
14131413 /// This is implemented as an intrinsic to avoid converting to and from an
14141414 /// integer, since the conversion would throw away aliasing information.
14151415 ///
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+ ///
14161420 /// # Safety
14171421 ///
14181422 /// Both the starting and resulting pointer must be either in bounds or one
@@ -1421,6 +1425,14 @@ extern "rust-intrinsic" {
14211425 /// returned value will result in undefined behavior.
14221426 ///
14231427 /// 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) ]
14241436 #[ must_use = "returns a new pointer rather than modifying its argument" ]
14251437 #[ rustc_const_stable( feature = "const_ptr_offset" , since = "1.61.0" ) ]
14261438 #[ rustc_nounwind]
Original file line number Diff line number Diff line change @@ -916,8 +916,16 @@ impl<T: ?Sized> *const T {
916916 where
917917 T : Sized ,
918918 {
919+ #[ cfg( bootstrap) ]
919920 // 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+ }
921929 }
922930
923931 /// 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 {
473473 where
474474 T : Sized ,
475475 {
476+ #[ cfg( bootstrap) ]
476477 // SAFETY: the caller must uphold the safety contract for `offset`.
477478 // The obtained pointer is valid for writes since the caller must
478479 // 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+ }
480490 }
481491
482492 /// Calculates the offset from a pointer in bytes.
@@ -1016,8 +1026,16 @@ impl<T: ?Sized> *mut T {
10161026 where
10171027 T : Sized ,
10181028 {
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) ) ]
10191035 // 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+ }
10211039 }
10221040
10231041 /// 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