Skip to content

Commit 481c8ab

Browse files
authored
Merge pull request #144 from RalfJung/miri
fix drain_range in Miri and add Miri to CI
2 parents 3095e0e + 9ed6941 commit 481c8ab

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ matrix:
2222
- rust: nightly
2323
env:
2424
- FEATURES='array-sizes-33-128 array-sizes-129-255'
25+
- name: "miri"
26+
script: sh ci/miri.sh
2527
branches:
2628
only:
2729
- master

ci/miri.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env sh
2+
3+
set -ex
4+
5+
export CARGO_NET_RETRY=5
6+
export CARGO_NET_TIMEOUT=10
7+
8+
MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)
9+
echo "Installing latest nightly with Miri: $MIRI_NIGHTLY"
10+
rustup default "$MIRI_NIGHTLY"
11+
12+
rustup component add miri
13+
cargo miri setup
14+
15+
cargo miri test -- -- -Zunstable-options --exclude-should-panic

src/char.rs

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub unsafe fn encode_utf8(ch: char, ptr: *mut u8, len: usize) -> Result<usize, E
6363

6464

6565
#[test]
66+
#[cfg(not(miri))] // Miri is too slow
6667
fn test_encode_utf8() {
6768
// Test that all codepoints are encoded correctly
6869
let mut data = [0u8; 16];

src/lib.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -598,12 +598,15 @@ impl<A: Array> ArrayVec<A> {
598598
fn drain_range(&mut self, start: usize, end: usize) -> Drain<A>
599599
{
600600
let len = self.len();
601-
// bounds check happens here
601+
602+
// bounds check happens here (before length is changed!)
602603
let range_slice: *const _ = &self[start..end];
603604

605+
// Calling `set_len` creates a fresh and thus unique mutable references, making all
606+
// older aliases we created invalid. So we cannot call that function.
607+
self.len = Index::from(start);
608+
604609
unsafe {
605-
// set self.vec length's to start, to be safe in case Drain is leaked
606-
self.set_len(start);
607610
Drain {
608611
tail_start: end,
609612
tail_len: len - end,

tests/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ fn test_drop() {
165165
}
166166

167167
#[test]
168+
#[cfg(not(miri))] // Miri does not support unwinding
168169
fn test_drop_panics() {
169170
use std::cell::Cell;
170171
use std::panic::catch_unwind;

0 commit comments

Comments
 (0)