about summary refs log tree commit diff
path: root/src/libcore/ptr/const_ptr.rs
diff options
context:
space:
mode:
authorLeSeulArtichaut <leseulartichaut@gmail.com>2020-05-01 19:49:56 +0200
committerLeSeulArtichaut <leseulartichaut@gmail.com>2020-05-01 19:49:56 +0200
commitd61debac64af9d9f0c18db55fe66144941aa76c7 (patch)
tree8eb635b07dbd9a2650135eb7be17ff3e70057dfc /src/libcore/ptr/const_ptr.rs
parenta91d64873f5b8daa43f0e82dedad7e2bc39e8fba (diff)
downloadrust-d61debac64af9d9f0c18db55fe66144941aa76c7.tar.gz
rust-d61debac64af9d9f0c18db55fe66144941aa76c7.zip
Document unsafety for `*const T` and `*mut T`
Diffstat (limited to 'src/libcore/ptr/const_ptr.rs')
-rw-r--r--src/libcore/ptr/const_ptr.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/libcore/ptr/const_ptr.rs b/src/libcore/ptr/const_ptr.rs
index 35a0852bbf5..94ad77d1ec6 100644
--- a/src/libcore/ptr/const_ptr.rs
+++ b/src/libcore/ptr/const_ptr.rs
@@ -3,8 +3,6 @@ use crate::cmp::Ordering::{self, Equal, Greater, Less};
 use crate::intrinsics;
 use crate::mem;
 
-// ignore-tidy-undocumented-unsafe
-
 #[lang = "const_ptr"]
 impl<T: ?Sized> *const T {
     /// Returns `true` if the pointer is null.
@@ -215,6 +213,7 @@ impl<T: ?Sized> *const T {
     where
         T: Sized,
     {
+        // SAFETY: the `arith_offset` intrinsic has no prerequisites to be called.
         unsafe { intrinsics::arith_offset(self, count) }
     }
 
@@ -702,6 +701,7 @@ impl<T: ?Sized> *const T {
         if !align.is_power_of_two() {
             panic!("align_offset: align is not a power-of-two");
         }
+        // SAFETY: `align` has been checked to be a power of 2 above
         unsafe { align_offset(self, align) }
     }
 }
@@ -729,6 +729,8 @@ impl<T> *const [T] {
     #[unstable(feature = "slice_ptr_len", issue = "71146")]
     #[rustc_const_unstable(feature = "const_slice_ptr_len", issue = "71146")]
     pub const fn len(self) -> usize {
+        // SAFETY: this is safe because `*const [T]` and `FatPtr<T>` have the same layout.
+        // Only `std` can make this guarantee.
         unsafe { Repr { rust: self }.raw }.len
     }
 }