File tree 4 files changed +12
-0
lines changed
4 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -1493,11 +1493,13 @@ mod prim_ref {}
1493
1493
/// However, a direct cast back is not possible. You need to use `transmute`:
1494
1494
///
1495
1495
/// ```rust
1496
+ /// # #[cfg(not(miri))] { // FIXME: use strict provenance APIs once they are stable, then remove this `cfg`
1496
1497
/// # let fnptr: fn(i32) -> i32 = |x| x+2;
1497
1498
/// # let fnptr_addr = fnptr as usize;
1498
1499
/// let fnptr = fnptr_addr as *const ();
1499
1500
/// let fnptr: fn(i32) -> i32 = unsafe { std::mem::transmute(fnptr) };
1500
1501
/// assert_eq!(fnptr(40), 42);
1502
+ /// # }
1501
1503
/// ```
1502
1504
///
1503
1505
/// 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 {
112
112
///
113
113
/// ```
114
114
/// #![feature(ptr_to_from_bits)]
115
+ /// # #[cfg(not(miri))] { // doctest does not work with strict provenance
115
116
/// let array = [13, 42];
116
117
/// let p0: *const i32 = &array[0];
117
118
/// assert_eq!(<*const _>::from_bits(p0.to_bits()), p0);
118
119
/// let p1: *const i32 = &array[1];
119
120
/// assert_eq!(p1.to_bits() - p0.to_bits(), 4);
121
+ /// # }
120
122
/// ```
121
123
#[ unstable( feature = "ptr_to_from_bits" , issue = "91126" ) ]
122
124
#[ deprecated(
@@ -140,9 +142,11 @@ impl<T: ?Sized> *const T {
140
142
///
141
143
/// ```
142
144
/// #![feature(ptr_to_from_bits)]
145
+ /// # #[cfg(not(miri))] { // doctest does not work with strict provenance
143
146
/// use std::ptr::NonNull;
144
147
/// let dangling: *const u8 = NonNull::dangling().as_ptr();
145
148
/// assert_eq!(<*const u8>::from_bits(1), dangling);
149
+ /// # }
146
150
/// ```
147
151
#[ unstable( feature = "ptr_to_from_bits" , issue = "91126" ) ]
148
152
#[ deprecated(
Original file line number Diff line number Diff line change @@ -117,12 +117,14 @@ impl<T: ?Sized> *mut T {
117
117
///
118
118
/// ```
119
119
/// #![feature(ptr_to_from_bits)]
120
+ /// # #[cfg(not(miri))] { // doctest does not work with strict provenance
120
121
/// let mut array = [13, 42];
121
122
/// let mut it = array.iter_mut();
122
123
/// let p0: *mut i32 = it.next().unwrap();
123
124
/// assert_eq!(<*mut _>::from_bits(p0.to_bits()), p0);
124
125
/// let p1: *mut i32 = it.next().unwrap();
125
126
/// assert_eq!(p1.to_bits() - p0.to_bits(), 4);
127
+ /// }
126
128
/// ```
127
129
#[ unstable( feature = "ptr_to_from_bits" , issue = "91126" ) ]
128
130
#[ deprecated(
@@ -146,9 +148,11 @@ impl<T: ?Sized> *mut T {
146
148
///
147
149
/// ```
148
150
/// #![feature(ptr_to_from_bits)]
151
+ /// # #[cfg(not(miri))] { // doctest does not work with strict provenance
149
152
/// use std::ptr::NonNull;
150
153
/// let dangling: *mut u8 = NonNull::dangling().as_ptr();
151
154
/// assert_eq!(<*mut u8>::from_bits(1), dangling);
155
+ /// }
152
156
/// ```
153
157
#[ unstable( feature = "ptr_to_from_bits" , issue = "91126" ) ]
154
158
#[ deprecated(
Original file line number Diff line number Diff line change @@ -1493,11 +1493,13 @@ mod prim_ref {}
1493
1493
/// However, a direct cast back is not possible. You need to use `transmute`:
1494
1494
///
1495
1495
/// ```rust
1496
+ /// # #[cfg(not(miri))] { // FIXME: use strict provenance APIs once they are stable, then remove this `cfg`
1496
1497
/// # let fnptr: fn(i32) -> i32 = |x| x+2;
1497
1498
/// # let fnptr_addr = fnptr as usize;
1498
1499
/// let fnptr = fnptr_addr as *const ();
1499
1500
/// let fnptr: fn(i32) -> i32 = unsafe { std::mem::transmute(fnptr) };
1500
1501
/// assert_eq!(fnptr(40), 42);
1502
+ /// # }
1501
1503
/// ```
1502
1504
///
1503
1505
/// 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