File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -779,6 +779,15 @@ where
779779///
780780/// For `r: &T`, `from_ref(r)` is equivalent to `r as *const T`, but is a bit safer since it will
781781/// never silently change type or mutability, in particular if the code is refactored.
782+ ///
783+ /// The caller must ensure that the pointee outlives the pointer this function returns, or else it
784+ /// will end up pointing to garbage.
785+ ///
786+ /// The caller must also ensure that the memory the pointer (non-transitively) points to is never
787+ /// written to (except inside an `UnsafeCell`) using this pointer or any pointer derived from it. If
788+ /// you need to mutate the pointee, use [`from_mut`]`. Specifically, to turn a mutable reference `m:
789+ /// &mut T` into `*const T`, prefer `from_mut(m).cast_const()` to obtain a pointer that can later be
790+ /// used for mutation.
782791#[ inline( always) ]
783792#[ must_use]
784793#[ stable( feature = "ptr_from_ref" , since = "1.76.0" ) ]
@@ -791,6 +800,9 @@ pub const fn from_ref<T: ?Sized>(r: &T) -> *const T {
791800
792801/// Convert a mutable reference to a raw pointer.
793802///
803+ /// The caller must ensure that the pointee outlives the pointer this function returns, or else it
804+ /// will end up pointing to garbage.
805+ ///
794806/// For `r: &mut T`, `from_mut(r)` is equivalent to `r as *mut T`, but is a bit safer since it will
795807/// never silently change type or mutability, in particular if the code is refactored.
796808#[ inline( always) ]
You can’t perform that action at this time.
0 commit comments