about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2018-07-18 12:50:13 -0700
committerJosh Triplett <josh@joshtriplett.org>2018-07-18 13:00:35 -0700
commitce756321ba888c7701cb81febd1de2bd98f87724 (patch)
tree7b7783844717c800d85a8ef9cfb046b53bc9c864 /src
parent12ed235adc62e63b16bb4f715b143c37a5efa00d (diff)
downloadrust-ce756321ba888c7701cb81febd1de2bd98f87724.tar.gz
rust-ce756321ba888c7701cb81febd1de2bd98f87724.zip
Document that Unique::empty() and NonNull::dangling() aren't sentinel values
The documentation of Unique::empty() and NonNull::dangling() could
potentially suggest that they work as sentinel values indicating a
not-yet-initialized pointer. However, they both declare a non-null
pointer equal to the alignment of the type, which could potentially
reference a valid value of that type (specifically, the first such valid
value in memory). Explicitly document that the return value of these
functions does not work as a sentinel value.
Diffstat (limited to 'src')
-rw-r--r--src/libcore/ptr.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index 0af642258c2..d8e061496d9 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -2703,6 +2703,11 @@ impl<T: Sized> Unique<T> {
     ///
     /// This is useful for initializing types which lazily allocate, like
     /// `Vec::new` does.
+    ///
+    /// Note that the pointer value may potentially represent a valid pointer to
+    /// a `T`, which means this must not be used as a "not yet initialized"
+    /// sentinel value. Types that lazily allocate must track initialization by
+    /// some other means.
     // FIXME: rename to dangling() to match NonNull?
     pub const fn empty() -> Self {
         unsafe {
@@ -2834,6 +2839,11 @@ impl<T: Sized> NonNull<T> {
     ///
     /// This is useful for initializing types which lazily allocate, like
     /// `Vec::new` does.
+    ///
+    /// Note that the pointer value may potentially represent a valid pointer to
+    /// a `T`, which means this must not be used as a "not yet initialized"
+    /// sentinel value. Types that lazily allocate must track initialization by
+    /// some other means.
     #[stable(feature = "nonnull", since = "1.25.0")]
     pub fn dangling() -> Self {
         unsafe {