This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -555,7 +555,11 @@ pub const fn null_mut<T>() -> *mut T {
555555#[ unstable( feature = "strict_provenance" , issue = "95228" ) ]
556556pub const fn invalid < T > ( addr : usize ) -> * const T {
557557 // FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
558- addr as * const T
558+ // We use transmute rather than a cast so tools like Miri can tell that this
559+ // is *not* the same as from_exposed_addr.
560+ // SAFETY: every valid integer is also a valid pointer (as long as you don't dereference that
561+ // pointer).
562+ unsafe { mem:: transmute ( addr) }
559563}
560564
561565/// Creates an invalid mutable pointer with the given address.
@@ -582,7 +586,11 @@ pub const fn invalid<T>(addr: usize) -> *const T {
582586#[ unstable( feature = "strict_provenance" , issue = "95228" ) ]
583587pub const fn invalid_mut < T > ( addr : usize ) -> * mut T {
584588 // FIXME(strict_provenance_magic): I am magic and should be a compiler intrinsic.
585- addr as * mut T
589+ // We use transmute rather than a cast so tools like Miri can tell that this
590+ // is *not* the same as from_exposed_addr.
591+ // SAFETY: every valid integer is also a valid pointer (as long as you don't dereference that
592+ // pointer).
593+ unsafe { mem:: transmute ( addr) }
586594}
587595
588596/// Convert an address back to a pointer, picking up a previously 'exposed' provenance.
You can’t perform that action at this time.
0 commit comments