Skip to content

Commit

Permalink
Fix miri tests
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Sep 24, 2023
1 parent e0741e8 commit a197225
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 13 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
- run: cargo build --workspace

miri:
miri_rune:
runs-on: ubuntu-latest
needs: basics
steps:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions crates/rune-alloc/src/alloc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,25 +144,31 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
/// 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
Expand Down
5 changes: 4 additions & 1 deletion crates/rune-alloc/src/alloc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1640,12 +1640,15 @@ impl<A: Allocator> String<A> {
/// # 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
Expand Down
3 changes: 2 additions & 1 deletion crates/rune-alloc/src/alloc/vec/drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions crates/rune-alloc/src/alloc/vec/into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,22 @@ impl<T, A: Allocator> IntoIter<T, A> {
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::<u8>::with_capacity(10).into_iter();
/// # use rune_alloc::Vec;
/// # #[cfg(not(miri))]
/// # fn main() -> Result<(), rune_alloc::Error> {
/// # let mut into_iter = Vec::<u8>::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
Expand Down
10 changes: 8 additions & 2 deletions crates/rune-alloc/src/alloc/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,8 @@ impl<T, A: Allocator> Vec<T, A> {
/// 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],
Expand All @@ -1175,7 +1177,8 @@ impl<T, A: Allocator> Vec<T, A> {
/// 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
Expand Down Expand Up @@ -2064,11 +2067,14 @@ impl<T, A: Allocator> Vec<T, A> {
/// 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]
Expand Down

0 comments on commit a197225

Please sign in to comment.