Skip to content

disable strict-provenance-violating doctests in Miri #104710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions library/core/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,11 +1493,13 @@ mod prim_ref {}
/// However, a direct cast back is not possible. You need to use `transmute`:
///
/// ```rust
/// # #[cfg(not(miri))] { // FIXME: use strict provenance APIs once they are stable, then remove this `cfg`
/// # let fnptr: fn(i32) -> i32 = |x| x+2;
/// # let fnptr_addr = fnptr as usize;
/// let fnptr = fnptr_addr as *const ();
/// let fnptr: fn(i32) -> i32 = unsafe { std::mem::transmute(fnptr) };
/// assert_eq!(fnptr(40), 42);
/// # }
/// ```
///
/// Crucially, we `as`-cast to a raw pointer before `transmute`ing to a function pointer.
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ impl<T: ?Sized> *const T {
///
/// ```
/// #![feature(ptr_to_from_bits)]
/// # #[cfg(not(miri))] { // doctest does not work with strict provenance
/// let array = [13, 42];
/// let p0: *const i32 = &array[0];
/// assert_eq!(<*const _>::from_bits(p0.to_bits()), p0);
/// let p1: *const i32 = &array[1];
/// assert_eq!(p1.to_bits() - p0.to_bits(), 4);
/// # }
/// ```
#[unstable(feature = "ptr_to_from_bits", issue = "91126")]
#[deprecated(
Expand All @@ -140,9 +142,11 @@ impl<T: ?Sized> *const T {
///
/// ```
/// #![feature(ptr_to_from_bits)]
/// # #[cfg(not(miri))] { // doctest does not work with strict provenance
/// use std::ptr::NonNull;
/// let dangling: *const u8 = NonNull::dangling().as_ptr();
/// assert_eq!(<*const u8>::from_bits(1), dangling);
/// # }
/// ```
#[unstable(feature = "ptr_to_from_bits", issue = "91126")]
#[deprecated(
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ impl<T: ?Sized> *mut T {
///
/// ```
/// #![feature(ptr_to_from_bits)]
/// # #[cfg(not(miri))] { // doctest does not work with strict provenance
/// let mut array = [13, 42];
/// let mut it = array.iter_mut();
/// let p0: *mut i32 = it.next().unwrap();
/// assert_eq!(<*mut _>::from_bits(p0.to_bits()), p0);
/// let p1: *mut i32 = it.next().unwrap();
/// assert_eq!(p1.to_bits() - p0.to_bits(), 4);
/// }
/// ```
#[unstable(feature = "ptr_to_from_bits", issue = "91126")]
#[deprecated(
Expand All @@ -146,9 +148,11 @@ impl<T: ?Sized> *mut T {
///
/// ```
/// #![feature(ptr_to_from_bits)]
/// # #[cfg(not(miri))] { // doctest does not work with strict provenance
/// use std::ptr::NonNull;
/// let dangling: *mut u8 = NonNull::dangling().as_ptr();
/// assert_eq!(<*mut u8>::from_bits(1), dangling);
/// }
/// ```
#[unstable(feature = "ptr_to_from_bits", issue = "91126")]
#[deprecated(
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,11 +1493,13 @@ mod prim_ref {}
/// However, a direct cast back is not possible. You need to use `transmute`:
///
/// ```rust
/// # #[cfg(not(miri))] { // FIXME: use strict provenance APIs once they are stable, then remove this `cfg`
/// # let fnptr: fn(i32) -> i32 = |x| x+2;
/// # let fnptr_addr = fnptr as usize;
/// let fnptr = fnptr_addr as *const ();
/// let fnptr: fn(i32) -> i32 = unsafe { std::mem::transmute(fnptr) };
/// assert_eq!(fnptr(40), 42);
/// # }
/// ```
///
/// Crucially, we `as`-cast to a raw pointer before `transmute`ing to a function pointer.
Expand Down