From a1972250105e0d5c527658ec036e76771ac2f53b Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Sun, 24 Sep 2023 14:59:52 +0200 Subject: [PATCH] Fix miri tests --- .github/workflows/ci.yml | 17 ++++++++++++++--- crates/rune-alloc/src/alloc/boxed.rs | 10 ++++++++-- crates/rune-alloc/src/alloc/string.rs | 5 ++++- crates/rune-alloc/src/alloc/vec/drain.rs | 3 ++- crates/rune-alloc/src/alloc/vec/into_iter.rs | 13 +++++++++---- crates/rune-alloc/src/alloc/vec/mod.rs | 10 ++++++++-- 6 files changed, 45 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2195ca4af..a71003ecb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,7 @@ jobs: - uses: Swatinem/rust-cache@v2 - run: cargo build --workspace - miri: + miri_rune: runs-on: ubuntu-latest needs: basics steps: @@ -71,7 +71,18 @@ jobs: with: components: miri - uses: Swatinem/rust-cache@v2 - - run: cargo +nightly miri test -p rune --all-features -- runtime hir::arena + - run: cargo miri test -p rune --all-features -- runtime hir::arena + + miri_rune_alloc: + runs-on: ubuntu-latest + needs: basics + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + with: + components: miri + - uses: Swatinem/rust-cache@v2 + - run: cargo miri test -p rune-alloc --all-features no_default_features: runs-on: ubuntu-latest @@ -108,7 +119,7 @@ jobs: test: runs-on: ubuntu-latest - needs: [no_default_features, build_feature, docs, msrv, miri, wasm] + needs: [no_default_features, build_feature, docs, msrv, miri_rune, miri_rune_alloc, wasm] steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable diff --git a/crates/rune-alloc/src/alloc/boxed.rs b/crates/rune-alloc/src/alloc/boxed.rs index 253a789a7..58898bc8a 100644 --- a/crates/rune-alloc/src/alloc/boxed.rs +++ b/crates/rune-alloc/src/alloc/boxed.rs @@ -144,25 +144,31 @@ impl Box { /// Simple usage: /// /// ``` + /// # #[cfg(not(miri))] + /// # fn main() -> Result<(), rune_alloc::Error> { /// use rune_alloc::Box; /// /// let x = Box::new(41)?; /// let static_ref: &'static mut usize = Box::leak(x); /// *static_ref += 1; /// assert_eq!(*static_ref, 42); - /// # Ok::<_, rune_alloc::Error>(()) + /// # Ok::<_, rune_alloc::Error>(()) } + /// # #[cfg(miri)] fn main() {} /// ``` /// /// Unsized data: /// /// ``` + /// # #[cfg(not(miri))] + /// # fn main() -> Result<(), rune_alloc::Error> { /// use rune_alloc::Box; /// /// let x = rune_alloc::try_vec![1, 2, 3].try_into_boxed_slice()?; /// let static_ref = Box::leak(x); /// static_ref[0] = 4; /// assert_eq!(*static_ref, [4, 2, 3]); - /// # Ok::<_, rune_alloc::Error>(()) + /// # Ok::<_, rune_alloc::Error>(()) } + /// # #[cfg(miri)] fn main() {} /// ``` #[inline] pub fn leak<'a>(b: Self) -> &'a mut T diff --git a/crates/rune-alloc/src/alloc/string.rs b/crates/rune-alloc/src/alloc/string.rs index 5b559620a..3749a9f63 100644 --- a/crates/rune-alloc/src/alloc/string.rs +++ b/crates/rune-alloc/src/alloc/string.rs @@ -1640,12 +1640,15 @@ impl String { /// # Examples /// /// ``` + /// # #[cfg(not(miri))] + /// # fn main() -> Result<(), rune_alloc::Error> { /// use rune_alloc::String; /// /// let x = String::try_from("bucket")?; /// let static_ref: &'static mut str = x.leak(); /// assert_eq!(static_ref, "bucket"); - /// # Ok::<_, rune_alloc::Error>(()) + /// # Ok::<_, rune_alloc::Error>(()) } + /// # #[cfg(miri)] fn main() {} /// ``` #[inline] pub fn leak<'a>(self) -> &'a mut str diff --git a/crates/rune-alloc/src/alloc/vec/drain.rs b/crates/rune-alloc/src/alloc/vec/drain.rs index 3b2855a43..750d06d5e 100644 --- a/crates/rune-alloc/src/alloc/vec/drain.rs +++ b/crates/rune-alloc/src/alloc/vec/drain.rs @@ -64,7 +64,7 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> { /// # Examples /// /// ``` - /// let mut vec = rune_alloc::vec!['a', 'b', 'c']; + /// let mut vec = rune_alloc::try_vec!['a', 'b', 'c']; /// let mut drain = vec.drain(..); /// /// assert_eq!(drain.next().unwrap(), 'a'); @@ -75,6 +75,7 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> { /// // If we wouldn't call `keep_rest()`, /// // `vec` would be empty. /// assert_eq!(vec, ['b', 'c']); + /// # Ok::<_, rune_alloc::Error>(()) /// ``` pub fn keep_rest(self) { // At this moment layout looks like this: diff --git a/crates/rune-alloc/src/alloc/vec/into_iter.rs b/crates/rune-alloc/src/alloc/vec/into_iter.rs index 8d463070f..5816b07ed 100644 --- a/crates/rune-alloc/src/alloc/vec/into_iter.rs +++ b/crates/rune-alloc/src/alloc/vec/into_iter.rs @@ -81,17 +81,22 @@ impl IntoIter { ptr::slice_from_raw_parts_mut(self.ptr as *mut T, self.len()) } - /// Drops remaining elements and relinquishes the backing allocation. - /// This method guarantees it won't panic before relinquishing - /// the backing allocation. + /// Drops remaining elements and relinquishes the backing allocation. This + /// method guarantees it won't panic before relinquishing the backing + /// allocation. /// /// This is roughly equivalent to the following, but more efficient /// /// ``` - /// # let mut into_iter = Vec::::with_capacity(10).into_iter(); + /// # use rune_alloc::Vec; + /// # #[cfg(not(miri))] + /// # fn main() -> Result<(), rune_alloc::Error> { + /// # let mut into_iter = Vec::::with_capacity(10)?.into_iter(); /// let mut into_iter = std::mem::replace(&mut into_iter, Vec::new().into_iter()); /// (&mut into_iter).for_each(drop); /// std::mem::forget(into_iter); + /// # Ok::<_, rune_alloc::Error>(()) } + /// # #[cfg(miri)] fn main() {} /// ``` /// /// This method is used by in-place iteration, refer to the vec::in_place_collect diff --git a/crates/rune-alloc/src/alloc/vec/mod.rs b/crates/rune-alloc/src/alloc/vec/mod.rs index 36663688f..a1ebd313b 100644 --- a/crates/rune-alloc/src/alloc/vec/mod.rs +++ b/crates/rune-alloc/src/alloc/vec/mod.rs @@ -1164,6 +1164,8 @@ impl Vec { /// the inner vectors were not freed prior to the `set_len` call: /// /// ``` + /// # #[cfg(not(miri))] + /// # fn main() -> Result<(), rune_alloc::Error> { /// use rune_alloc::try_vec; /// /// let mut vec = try_vec![try_vec![1, 0, 0], @@ -1175,7 +1177,8 @@ impl Vec { /// unsafe { /// vec.set_len(0); /// } - /// # Ok::<_, rune_alloc::Error>(()) + /// # Ok::<_, rune_alloc::Error>(()) } + /// # #[cfg(miri)] fn main() {} /// ``` /// /// Normally, here, one would use [`clear`] instead to correctly drop @@ -2064,11 +2067,14 @@ impl Vec { /// Simple usage: /// /// ``` + /// # #[cfg(not(miri))] + /// # fn main() -> Result<(), rune_alloc::Error> { /// let x = rune_alloc::try_vec![1, 2, 3]; /// let static_ref: &'static mut [usize] = x.leak(); /// static_ref[0] += 1; /// assert_eq!(static_ref, &[2, 2, 3]); - /// # Ok::<_, rune_alloc::Error>(()) + /// # Ok::<_, rune_alloc::Error>(()) } + /// # #[cfg(miri)] fn main() {} /// ``` #[inline] pub fn leak<'a>(self) -> &'a mut [T]