Skip to content

Commit 7bb50ae

Browse files
committed
run doctests (and add required patch)
1 parent a0b2580 commit 7bb50ae

File tree

3 files changed

+150
-4
lines changed

3 files changed

+150
-4
lines changed

rust-src.diff

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs
2+
index 04033905728..ef37fef0455 100644
3+
--- a/library/alloc/src/boxed.rs
4+
+++ b/library/alloc/src/boxed.rs
5+
@@ -793,7 +793,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
6+
/// use std::alloc::{Allocator, Layout, System};
7+
///
8+
/// unsafe {
9+
- /// let ptr = System.allocate(Layout::new::<i32>())?.as_mut_ptr();
10+
+ /// let ptr = System.allocate(Layout::new::<i32>())?.as_mut_ptr() as *mut i32;
11+
/// // In general .write is required to avoid attempting to destruct
12+
/// // the (uninitialized) previous contents of `ptr`, though for this
13+
/// // simple example `*ptr = 5` would have worked as well.
14+
diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs
15+
index 64342de6341..4d7d47579ee 100644
16+
--- a/library/core/src/mem/maybe_uninit.rs
17+
+++ b/library/core/src/mem/maybe_uninit.rs
18+
@@ -736,22 +736,22 @@ pub unsafe fn assume_init_drop(&mut self) {
19+
/// #![feature(maybe_uninit_ref)]
20+
/// use std::mem::MaybeUninit;
21+
///
22+
- /// # unsafe extern "C" fn initialize_buffer(buf: *mut [u8; 2048]) { *buf = [0; 2048] }
23+
+ /// # unsafe extern "C" fn initialize_buffer(buf: *mut [u8; 1024]) { *buf = [0; 1024] }
24+
/// # #[cfg(FALSE)]
25+
/// extern "C" {
26+
/// /// Initializes *all* the bytes of the input buffer.
27+
- /// fn initialize_buffer(buf: *mut [u8; 2048]);
28+
+ /// fn initialize_buffer(buf: *mut [u8; 1024]);
29+
/// }
30+
///
31+
- /// let mut buf = MaybeUninit::<[u8; 2048]>::uninit();
32+
+ /// let mut buf = MaybeUninit::<[u8; 1024]>::uninit();
33+
///
34+
/// // Initialize `buf`:
35+
/// unsafe { initialize_buffer(buf.as_mut_ptr()); }
36+
/// // Now we know that `buf` has been initialized, so we could `.assume_init()` it.
37+
- /// // However, using `.assume_init()` may trigger a `memcpy` of the 2048 bytes.
38+
+ /// // However, using `.assume_init()` may trigger a `memcpy` of the 1024 bytes.
39+
/// // To assert our buffer has been initialized without copying it, we upgrade
40+
- /// // the `&mut MaybeUninit<[u8; 2048]>` to a `&mut [u8; 2048]`:
41+
- /// let buf: &mut [u8; 2048] = unsafe {
42+
+ /// // the `&mut MaybeUninit<[u8; 1024]>` to a `&mut [u8; 1024]`:
43+
+ /// let buf: &mut [u8; 1024] = unsafe {
44+
/// // SAFETY: `buf` has been initialized.
45+
/// buf.assume_init_mut()
46+
/// };
47+
diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs
48+
index f18387d020d..4571ba154ea 100644
49+
--- a/library/core/src/ptr/const_ptr.rs
50+
+++ b/library/core/src/ptr/const_ptr.rs
51+
@@ -724,7 +724,7 @@ pub const fn wrapping_sub(self, count: usize) -> Self
52+
/// #![feature(set_ptr_value)]
53+
/// # use core::fmt::Debug;
54+
/// let arr: [i32; 3] = [1, 2, 3];
55+
- /// let mut ptr = &arr[0] as *const dyn Debug;
56+
+ /// let mut ptr = arr.as_ptr() as *const dyn Debug;
57+
/// let thin = ptr as *const u8;
58+
/// unsafe {
59+
/// ptr = ptr.set_ptr_value(thin.add(8));
60+
diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs
61+
index 3c6f1978283..ba08823e343 100644
62+
--- a/library/core/src/ptr/mut_ptr.rs
63+
+++ b/library/core/src/ptr/mut_ptr.rs
64+
@@ -830,7 +830,7 @@ pub const fn wrapping_sub(self, count: usize) -> Self
65+
/// #![feature(set_ptr_value)]
66+
/// # use core::fmt::Debug;
67+
/// let mut arr: [i32; 3] = [1, 2, 3];
68+
- /// let mut ptr = &mut arr[0] as *mut dyn Debug;
69+
+ /// let mut ptr = arr.as_mut_ptr() as *mut dyn Debug;
70+
/// let thin = ptr as *mut u8;
71+
/// unsafe {
72+
/// ptr = ptr.set_ptr_value(thin.add(8));
73+
diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs
74+
index bf70b28579c..9085d5c7b97 100644
75+
--- a/library/core/src/sync/atomic.rs
76+
+++ b/library/core/src/sync/atomic.rs
77+
@@ -78,7 +78,7 @@
78+
//! ```
79+
//! use std::sync::Arc;
80+
//! use std::sync::atomic::{AtomicUsize, Ordering};
81+
-//! use std::thread;
82+
+//! use std::{hint, thread};
83+
//!
84+
//! fn main() {
85+
//! let spinlock = Arc::new(AtomicUsize::new(1));
86+
@@ -89,7 +89,9 @@
87+
//! });
88+
//!
89+
//! // Wait for the other thread to release the lock
90+
-//! while spinlock.load(Ordering::SeqCst) != 0 {}
91+
+//! while spinlock.load(Ordering::SeqCst) != 0 {
92+
+//! hint::spin_loop();
93+
+//! }
94+
//!
95+
//! if let Err(panic) = thread.join() {
96+
//! println!("Thread had an error: {:?}", panic);
97+
@@ -898,8 +900,10 @@ pub const fn new(p: *mut T) -> AtomicPtr<T> {
98+
/// ```
99+
/// use std::sync::atomic::{AtomicPtr, Ordering};
100+
///
101+
- /// let mut atomic_ptr = AtomicPtr::new(&mut 10);
102+
- /// *atomic_ptr.get_mut() = &mut 5;
103+
+ /// let mut data = 10;
104+
+ /// let mut atomic_ptr = AtomicPtr::new(&mut data);
105+
+ /// let mut other_data = 5;
106+
+ /// *atomic_ptr.get_mut() = &mut other_data;
107+
/// assert_eq!(unsafe { *atomic_ptr.load(Ordering::SeqCst) }, 5);
108+
/// ```
109+
#[inline]
110+
@@ -916,9 +920,11 @@ pub fn get_mut(&mut self) -> &mut *mut T {
111+
/// #![feature(atomic_from_mut)]
112+
/// use std::sync::atomic::{AtomicPtr, Ordering};
113+
///
114+
- /// let mut some_ptr = &mut 123 as *mut i32;
115+
+ /// let mut data = 123;
116+
+ /// let mut some_ptr = &mut data as *mut i32;
117+
/// let a = AtomicPtr::from_mut(&mut some_ptr);
118+
- /// a.store(&mut 456, Ordering::Relaxed);
119+
+ /// let mut other_data = 456;
120+
+ /// a.store(&mut other_data, Ordering::Relaxed);
121+
/// assert_eq!(unsafe { *some_ptr }, 456);
122+
/// ```
123+
#[inline]
124+
@@ -944,7 +950,8 @@ pub fn from_mut(v: &mut *mut T) -> &Self {
125+
/// ```
126+
/// use std::sync::atomic::AtomicPtr;
127+
///
128+
- /// let atomic_ptr = AtomicPtr::new(&mut 5);
129+
+ /// let mut data = 5;
130+
+ /// let atomic_ptr = AtomicPtr::new(&mut data);
131+
/// assert_eq!(unsafe { *atomic_ptr.into_inner() }, 5);
132+
/// ```
133+
#[inline]

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2021-04-06
1+
nightly-2021-04-10

travis.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,22 @@ cp -a $(rustc --print sysroot)/lib/rustlib/src/rust/ rust-src-patched
88

99
# run the tests (some also without validation, to exercise those code paths in Miri)
1010
export RUST_SRC=rust-src-patched
11+
12+
# libcore
1113
echo && echo "## Testing core (no validation, no Stacked Borrows, symbolic alignment)" && echo
12-
MIRIFLAGS="-Zmiri-disable-validation -Zmiri-disable-stacked-borrows -Zmiri-symbolic-alignment-check" ./run-test.sh core --lib --tests -- --skip align 2>&1 | ts -i '%.s '
14+
MIRIFLAGS="-Zmiri-disable-validation -Zmiri-disable-stacked-borrows -Zmiri-symbolic-alignment-check" \
15+
./run-test.sh core --all-targets -- --skip align 2>&1 | ts -i '%.s '
1316
echo && echo "## Testing core" && echo
14-
./run-test.sh core --lib --tests 2>&1 | ts -i '%.s '
17+
MIRIFLAGS="" \
18+
./run-test.sh core --all-targets 2>&1 | ts -i '%.s '
19+
echo && echo "## Testing core (doctests)" && echo
20+
MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-disable-isolation" \
21+
./run-test.sh core --doc
22+
23+
# liballoc
1524
echo && echo "## Testing alloc (symbolic alignment)" && echo
16-
MIRIFLAGS="-Zmiri-symbolic-alignment-check" ./run-test.sh alloc --lib --tests 2>&1 | ts -i '%.s '
25+
MIRIFLAGS="-Zmiri-symbolic-alignment-check" \
26+
./run-test.sh alloc --all-targets 2>&1 | ts -i '%.s '
27+
echo && echo "## Testing alloc (doctests)" && echo
28+
MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-disable-isolation" \
29+
./run-test.sh alloc --doc

0 commit comments

Comments
 (0)