65
65
//! [`write_volatile`]: ./fn.write_volatile.html
66
66
//! [`NonNull::dangling`]: ./struct.NonNull.html#method.dangling
67
67
68
- // ignore-tidy-undocumented-unsafe
69
-
70
68
#![ stable( feature = "rust1" , since = "1.0.0" ) ]
71
69
72
70
use crate :: intrinsics;
@@ -251,6 +249,7 @@ pub(crate) struct FatPtr<T> {
251
249
#[ inline]
252
250
#[ unstable( feature = "slice_from_raw_parts" , reason = "recently added" , issue = "36925" ) ]
253
251
pub fn slice_from_raw_parts < T > ( data : * const T , len : usize ) -> * const [ T ] {
252
+ // SAFETY: FatPtr.data and Repr.rust are both usize in the same location
254
253
unsafe { Repr { raw : FatPtr { data, len } } . rust }
255
254
}
256
255
@@ -267,6 +266,7 @@ pub fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
267
266
#[ inline]
268
267
#[ unstable( feature = "slice_from_raw_parts" , reason = "recently added" , issue = "36925" ) ]
269
268
pub fn slice_from_raw_parts_mut < T > ( data : * mut T , len : usize ) -> * mut [ T ] {
269
+ // SAFETY: FatPtr.data and Repr.rust_mut are both usize in the same location
270
270
unsafe { Repr { raw : FatPtr { data, len } } . rust_mut }
271
271
}
272
272
@@ -1233,6 +1233,7 @@ impl<T: ?Sized> *const T {
1233
1233
#[ stable( feature = "ptr_wrapping_offset" , since = "1.16.0" ) ]
1234
1234
#[ inline]
1235
1235
pub fn wrapping_offset ( self , count : isize ) -> * const T where T : Sized {
1236
+ // SAFETY: see documentation
1236
1237
unsafe {
1237
1238
intrinsics:: arith_offset ( self , count)
1238
1239
}
@@ -1723,6 +1724,7 @@ impl<T: ?Sized> *const T {
1723
1724
if !align. is_power_of_two ( ) {
1724
1725
panic ! ( "align_offset: align is not a power-of-two" ) ;
1725
1726
}
1727
+ // SAFETY: align is a power of two
1726
1728
unsafe {
1727
1729
align_offset ( self , align)
1728
1730
}
@@ -1931,6 +1933,7 @@ impl<T: ?Sized> *mut T {
1931
1933
#[ stable( feature = "ptr_wrapping_offset" , since = "1.16.0" ) ]
1932
1934
#[ inline]
1933
1935
pub fn wrapping_offset ( self , count : isize ) -> * mut T where T : Sized {
1936
+ // SAFETY: see documentation
1934
1937
unsafe {
1935
1938
intrinsics:: arith_offset ( self , count) as * mut T
1936
1939
}
@@ -2574,6 +2577,7 @@ impl<T: ?Sized> *mut T {
2574
2577
if !align. is_power_of_two ( ) {
2575
2578
panic ! ( "align_offset: align is not a power-of-two" ) ;
2576
2579
}
2580
+ // SAFETY: align is a power of two
2577
2581
unsafe {
2578
2582
align_offset ( self , align)
2579
2583
}
0 commit comments