Skip to content

Commit 9b7f9c4

Browse files
committed
take more clarifying text from Gankra's PR
original source: #95851
1 parent 6c73f25 commit 9b7f9c4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

library/core/src/ptr/const_ptr.rs

+7
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,13 @@ impl<T: ?Sized> *const T {
611611
/// except that it has a lot more opportunities for UB, in exchange for the compiler
612612
/// better understanding what you are doing.
613613
///
614+
/// The primary motivation of this method is for computing the `len` of an array/slice
615+
/// of `T` that you are currently representing as a "start" and "end" pointer
616+
/// (and "end" is "one past the end" of the array).
617+
/// In that case, `end.offset_from(start)` gets you the length of the array.
618+
///
619+
/// All of the following safety requirements are trivially satisfied for this usecase.
620+
///
614621
/// [`offset`]: #method.offset
615622
///
616623
/// # Safety

library/core/src/ptr/mut_ptr.rs

+7
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,13 @@ impl<T: ?Sized> *mut T {
785785
/// except that it has a lot more opportunities for UB, in exchange for the compiler
786786
/// better understanding what you are doing.
787787
///
788+
/// The primary motivation of this method is for computing the `len` of an array/slice
789+
/// of `T` that you are currently representing as a "start" and "end" pointer
790+
/// (and "end" is "one past the end" of the array).
791+
/// In that case, `end.offset_from(start)` gets you the length of the array.
792+
///
793+
/// All of the following safety requirements are trivially satisfied for this usecase.
794+
///
788795
/// [`offset`]: pointer#method.offset-1
789796
///
790797
/// # Safety

0 commit comments

Comments
 (0)