about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-03-13 03:33:54 +0100
committerGitHub <noreply@github.com>2019-03-13 03:33:54 +0100
commit3623c1ac4edb92e2aabab14c0b36691e970703ea (patch)
tree749e9bd12ca639b8b8d3c6cbe3b67d7db200e8fc
parentb70a98f261d8cef1ba2b76a4d2d19b5076b04dbf (diff)
parent8ec8639bf3f8c7b17d91028f698abc3067cd56ea (diff)
downloadrust-3623c1ac4edb92e2aabab14c0b36691e970703ea.tar.gz
rust-3623c1ac4edb92e2aabab14c0b36691e970703ea.zip
Rollup merge of #59130 - RalfJung:non-null, r=rkruppe
Note that NonNull does not launder shared references for mutation

See https://users.rust-lang.org/t/relative-pointer-an-abstraction-to-build-movable-self-referential-types/26186/6
-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 d288ca449df..a9a029d606d 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -2874,6 +2874,16 @@ impl<'a, T: ?Sized> From<NonNull<T>> for Unique<T> {
 /// Usually this won't be necessary; covariance is correct for most safe abstractions,
 /// such as Box, Rc, Arc, Vec, and LinkedList. This is the case because they
 /// provide a public API that follows the normal shared XOR mutable rules of Rust.
+///
+/// Notice that `NonNull<T>` has a `From` instance for `&T`. However, this does
+/// not change the fact that mutating through a (pointer derived from a) shared
+/// reference is undefined behavior unless the mutation happens inside an
+/// [`UnsafeCell<T>`]. The same goes for creating a mutable reference from a shared
+/// reference. When using this `From` instance without an `UnsafeCell<T>`,
+/// it is your responsibility to ensure that `as_mut` is never called, and `as_ptr`
+/// is never used for mutation.
+///
+/// [`UnsafeCell<T>`]: ../cell/struct.UnsafeCell.html
 #[stable(feature = "nonnull", since = "1.25.0")]
 #[repr(transparent)]
 #[rustc_layout_scalar_valid_range_start(1)]