This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +12
-0
lines changed Expand file tree Collapse file tree 4 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -1493,11 +1493,13 @@ mod prim_ref {}
14931493/// However, a direct cast back is not possible. You need to use `transmute`:
14941494///
14951495/// ```rust
1496+ /// # #[cfg(not(miri))] { // FIXME: use strict provenance APIs once they are stable, then remove this `cfg`
14961497/// # let fnptr: fn(i32) -> i32 = |x| x+2;
14971498/// # let fnptr_addr = fnptr as usize;
14981499/// let fnptr = fnptr_addr as *const ();
14991500/// let fnptr: fn(i32) -> i32 = unsafe { std::mem::transmute(fnptr) };
15001501/// assert_eq!(fnptr(40), 42);
1502+ /// # }
15011503/// ```
15021504///
15031505/// Crucially, we `as`-cast to a raw pointer before `transmute`ing to a function pointer.
Original file line number Diff line number Diff line change @@ -112,11 +112,13 @@ impl<T: ?Sized> *const T {
112112 ///
113113 /// ```
114114 /// #![feature(ptr_to_from_bits)]
115+ /// # #[cfg(not(miri))] { // doctest does not work with strict provenance
115116 /// let array = [13, 42];
116117 /// let p0: *const i32 = &array[0];
117118 /// assert_eq!(<*const _>::from_bits(p0.to_bits()), p0);
118119 /// let p1: *const i32 = &array[1];
119120 /// assert_eq!(p1.to_bits() - p0.to_bits(), 4);
121+ /// # }
120122 /// ```
121123 #[ unstable( feature = "ptr_to_from_bits" , issue = "91126" ) ]
122124 #[ deprecated(
@@ -140,9 +142,11 @@ impl<T: ?Sized> *const T {
140142 ///
141143 /// ```
142144 /// #![feature(ptr_to_from_bits)]
145+ /// # #[cfg(not(miri))] { // doctest does not work with strict provenance
143146 /// use std::ptr::NonNull;
144147 /// let dangling: *const u8 = NonNull::dangling().as_ptr();
145148 /// assert_eq!(<*const u8>::from_bits(1), dangling);
149+ /// # }
146150 /// ```
147151 #[ unstable( feature = "ptr_to_from_bits" , issue = "91126" ) ]
148152 #[ deprecated(
Original file line number Diff line number Diff line change @@ -117,12 +117,14 @@ impl<T: ?Sized> *mut T {
117117 ///
118118 /// ```
119119 /// #![feature(ptr_to_from_bits)]
120+ /// # #[cfg(not(miri))] { // doctest does not work with strict provenance
120121 /// let mut array = [13, 42];
121122 /// let mut it = array.iter_mut();
122123 /// let p0: *mut i32 = it.next().unwrap();
123124 /// assert_eq!(<*mut _>::from_bits(p0.to_bits()), p0);
124125 /// let p1: *mut i32 = it.next().unwrap();
125126 /// assert_eq!(p1.to_bits() - p0.to_bits(), 4);
127+ /// }
126128 /// ```
127129 #[ unstable( feature = "ptr_to_from_bits" , issue = "91126" ) ]
128130 #[ deprecated(
@@ -146,9 +148,11 @@ impl<T: ?Sized> *mut T {
146148 ///
147149 /// ```
148150 /// #![feature(ptr_to_from_bits)]
151+ /// # #[cfg(not(miri))] { // doctest does not work with strict provenance
149152 /// use std::ptr::NonNull;
150153 /// let dangling: *mut u8 = NonNull::dangling().as_ptr();
151154 /// assert_eq!(<*mut u8>::from_bits(1), dangling);
155+ /// }
152156 /// ```
153157 #[ unstable( feature = "ptr_to_from_bits" , issue = "91126" ) ]
154158 #[ deprecated(
Original file line number Diff line number Diff line change @@ -1493,11 +1493,13 @@ mod prim_ref {}
14931493/// However, a direct cast back is not possible. You need to use `transmute`:
14941494///
14951495/// ```rust
1496+ /// # #[cfg(not(miri))] { // FIXME: use strict provenance APIs once they are stable, then remove this `cfg`
14961497/// # let fnptr: fn(i32) -> i32 = |x| x+2;
14971498/// # let fnptr_addr = fnptr as usize;
14981499/// let fnptr = fnptr_addr as *const ();
14991500/// let fnptr: fn(i32) -> i32 = unsafe { std::mem::transmute(fnptr) };
15001501/// assert_eq!(fnptr(40), 42);
1502+ /// # }
15011503/// ```
15021504///
15031505/// Crucially, we `as`-cast to a raw pointer before `transmute`ing to a function pointer.
You can’t perform that action at this time.
0 commit comments