diff options
| author | Ralf Jung <post@ralfj.de> | 2019-05-01 17:59:48 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2019-05-01 17:59:48 +0200 |
| commit | 1e47250540bc97f921d1b7e2982f1904fa191dff (patch) | |
| tree | 30c0e7841d8190f846c568f6bf44ca83ae75f70e /src/libcore | |
| parent | 6cc24f26036b28fb3366de86efe3da6c4464057a (diff) | |
| download | rust-1e47250540bc97f921d1b7e2982f1904fa191dff.tar.gz rust-1e47250540bc97f921d1b7e2982f1904fa191dff.zip | |
as_ptr returns a read-only pointer
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/slice/mod.rs | 6 | ||||
| -rw-r--r-- | src/libcore/str/mod.rs | 5 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 8731f486753..c273153fa5e 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -359,6 +359,10 @@ impl<T> [T] { /// The caller must ensure that the slice outlives the pointer this /// function returns, or else it will end up pointing to garbage. /// + /// The caller must also ensure that the memory the pointer (non-transitively) points to + /// is never written to (except inside an `UnsafeCell`). If you need to mutate + /// the contents of the slice, use [`as_mut_ptr`]. + /// /// Modifying the container referenced by this slice may cause its buffer /// to be reallocated, which would also make any pointers to it invalid. /// @@ -374,6 +378,8 @@ impl<T> [T] { /// } /// } /// ``` + /// + /// [`as_mut_ptr`]: #method.as_mut_ptr #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub const fn as_ptr(&self) -> *const T { diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 45421848cec..96a5ce61ca0 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -2188,7 +2188,12 @@ impl str { /// [`u8`]. This pointer will be pointing to the first byte of the string /// slice. /// + /// The caller must ensure that the memory the pointer points to + /// is never written to. If you need to mutate + /// the contents of the string slice, use [`as_mut_ptr`]. + /// /// [`u8`]: primitive.u8.html + /// [`as_mut_ptr`]: #method.as_mut_ptr /// /// # Examples /// |
