Skip to content
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

fix for Miri and add Miri to CI #27

Merged
merged 2 commits into from
Aug 2, 2019
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
16 changes: 12 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
sudo: false
language: rust
rust:
- nightly
- beta
- stable

matrix:
include:
- rust: stable
- rust: beta
- rust: nightly

- rust: nightly
os: linux
env: DESCRIPTION="Miri"
script:
- sh ci/miri.sh

script:
- cargo test
Expand Down
10 changes: 10 additions & 0 deletions ci/miri.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set -ex

MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)
echo "Installing latest nightly with Miri: $MIRI_NIGHTLY"
rustup default "$MIRI_NIGHTLY"

rustup component add miri
cargo miri setup

cargo miri test
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,13 @@ impl<T> Arena<T> {
#[inline]
fn alloc_fast_path(&self, value: T) -> Result<&mut T, T> {
let mut chunks = self.chunks.borrow_mut();
if chunks.current.len() < chunks.current.capacity() {
let len = chunks.current.len();
if len < chunks.current.capacity() {
chunks.current.push(value);
Ok(unsafe { mem::transmute(chunks.current.last_mut().unwrap()) })
// Avoid going through `Vec::deref_mut`, which overlaps
// other references we have already handed out!
debug_assert!(len < chunks.current.len()); // bounds check
Ok(unsafe { &mut *chunks.current.as_mut_ptr().add(len) })
} else {
Err(value)
}
Expand Down