Skip to content

Commit a40659d

Browse files
authored
Rollup merge of #104710 - RalfJung:doc-strict-provenance, r=thomcc
disable strict-provenance-violating doctests in Miri Most of these are on deprecated unstable functions anyway. This lets us run the remaining doctests with `-Zmiri-strict-provenance`, which I think is a win. r? `@thomcc`
2 parents b12d31f + 3a95e12 commit a40659d

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

library/core/src/primitive_docs.rs

+2
Original file line numberDiff line numberDiff 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.

library/core/src/ptr/const_ptr.rs

+4
Original file line numberDiff line numberDiff 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(

library/core/src/ptr/mut_ptr.rs

+4
Original file line numberDiff line numberDiff 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(

library/std/src/primitive_docs.rs

+2
Original file line numberDiff line numberDiff 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.

0 commit comments

Comments
 (0)