diff options
| author | Ralf Jung <post@ralfj.de> | 2023-09-26 16:41:06 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-09-26 16:41:06 +0200 |
| commit | 9b7f9c4328dde77396f815dc929de6cdbc700531 (patch) | |
| tree | 834698b5c3ffb1195136294d4b1c1d58da827c8b /library/core/src/ptr | |
| parent | 6c73f254b977574a2e155dc18c4f96746071f4e0 (diff) | |
| download | rust-9b7f9c4328dde77396f815dc929de6cdbc700531.tar.gz rust-9b7f9c4328dde77396f815dc929de6cdbc700531.zip | |
take more clarifying text from Gankra's PR
original source: https://github.com/rust-lang/rust/pull/95851
Diffstat (limited to 'library/core/src/ptr')
| -rw-r--r-- | library/core/src/ptr/const_ptr.rs | 7 | ||||
| -rw-r--r-- | library/core/src/ptr/mut_ptr.rs | 7 |
2 files changed, 14 insertions, 0 deletions
diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 3e68216e40e..9af8f1228f0 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -611,6 +611,13 @@ impl<T: ?Sized> *const T { /// except that it has a lot more opportunities for UB, in exchange for the compiler /// better understanding what you are doing. /// + /// The primary motivation of this method is for computing the `len` of an array/slice + /// of `T` that you are currently representing as a "start" and "end" pointer + /// (and "end" is "one past the end" of the array). + /// In that case, `end.offset_from(start)` gets you the length of the array. + /// + /// All of the following safety requirements are trivially satisfied for this usecase. + /// /// [`offset`]: #method.offset /// /// # Safety diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index c89ce52292a..109c286929b 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -785,6 +785,13 @@ impl<T: ?Sized> *mut T { /// except that it has a lot more opportunities for UB, in exchange for the compiler /// better understanding what you are doing. /// + /// The primary motivation of this method is for computing the `len` of an array/slice + /// of `T` that you are currently representing as a "start" and "end" pointer + /// (and "end" is "one past the end" of the array). + /// In that case, `end.offset_from(start)` gets you the length of the array. + /// + /// All of the following safety requirements are trivially satisfied for this usecase. + /// /// [`offset`]: pointer#method.offset-1 /// /// # Safety |
