Skip to content

Commit

Permalink
review failures in heap, slice, vec
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Feb 13, 2019
1 parent 4c1a1c3 commit 767dadf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/liballoc/tests/heap.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(not(miri))]

use std::alloc::{Global, Alloc, Layout, System};

/// Issue #45955.
Expand Down
22 changes: 20 additions & 2 deletions src/liballoc/tests/slice.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(not(miri))]

use std::cell::Cell;
use std::cmp::Ordering::{self, Equal, Greater, Less};
use std::mem;
Expand Down Expand Up @@ -260,6 +258,7 @@ fn test_swap_remove() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_swap_remove_fail() {
let mut v = vec![1];
let _ = v.swap_remove(0);
Expand Down Expand Up @@ -391,6 +390,7 @@ fn test_reverse() {
}

#[test]
#[cfg(not(miri))] // Miri does not support entropy
fn test_sort() {
let mut rng = thread_rng();

Expand Down Expand Up @@ -467,6 +467,7 @@ fn test_sort() {
}

#[test]
#[cfg(not(miri))] // Miri does not support entropy
fn test_sort_stability() {
for len in (2..25).chain(500..510) {
for _ in 0..10 {
Expand Down Expand Up @@ -631,6 +632,7 @@ fn test_insert() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_insert_oob() {
let mut a = vec![1, 2, 3];
a.insert(4, 5);
Expand All @@ -655,6 +657,7 @@ fn test_remove() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_remove_fail() {
let mut a = vec![1];
let _ = a.remove(0);
Expand Down Expand Up @@ -936,6 +939,7 @@ fn test_windowsator() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_windowsator_0() {
let v = &[1, 2, 3, 4];
let _it = v.windows(0);
Expand All @@ -960,6 +964,7 @@ fn test_chunksator() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_chunksator_0() {
let v = &[1, 2, 3, 4];
let _it = v.chunks(0);
Expand All @@ -984,6 +989,7 @@ fn test_chunks_exactator() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_chunks_exactator_0() {
let v = &[1, 2, 3, 4];
let _it = v.chunks_exact(0);
Expand All @@ -1008,6 +1014,7 @@ fn test_rchunksator() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_rchunksator_0() {
let v = &[1, 2, 3, 4];
let _it = v.rchunks(0);
Expand All @@ -1032,6 +1039,7 @@ fn test_rchunks_exactator() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_rchunks_exactator_0() {
let v = &[1, 2, 3, 4];
let _it = v.rchunks_exact(0);
Expand Down Expand Up @@ -1084,6 +1092,7 @@ fn test_vec_default() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_overflow_does_not_cause_segfault() {
let mut v = vec![];
v.reserve_exact(!0);
Expand All @@ -1093,6 +1102,7 @@ fn test_overflow_does_not_cause_segfault() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_overflow_does_not_cause_segfault_managed() {
let mut v = vec![Rc::new(1)];
v.reserve_exact(!0);
Expand Down Expand Up @@ -1268,6 +1278,7 @@ fn test_mut_chunks_rev() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_mut_chunks_0() {
let mut v = [1, 2, 3, 4];
let _it = v.chunks_mut(0);
Expand Down Expand Up @@ -1300,6 +1311,7 @@ fn test_mut_chunks_exact_rev() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_mut_chunks_exact_0() {
let mut v = [1, 2, 3, 4];
let _it = v.chunks_exact_mut(0);
Expand Down Expand Up @@ -1332,6 +1344,7 @@ fn test_mut_rchunks_rev() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_mut_rchunks_0() {
let mut v = [1, 2, 3, 4];
let _it = v.rchunks_mut(0);
Expand Down Expand Up @@ -1364,6 +1377,7 @@ fn test_mut_rchunks_exact_rev() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_mut_rchunks_exact_0() {
let mut v = [1, 2, 3, 4];
let _it = v.rchunks_exact_mut(0);
Expand Down Expand Up @@ -1397,6 +1411,7 @@ fn test_box_slice_clone() {
#[test]
#[allow(unused_must_use)] // here, we care about the side effects of `.clone()`
#[cfg_attr(target_os = "emscripten", ignore)]
#[cfg(not(miri))] // Miri does not support panics
fn test_box_slice_clone_panics() {
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
Expand Down Expand Up @@ -1461,6 +1476,7 @@ fn test_copy_from_slice() {

#[test]
#[should_panic(expected = "destination and source slices have different lengths")]
#[cfg(not(miri))] // Miri does not support panics
fn test_copy_from_slice_dst_longer() {
let src = [0, 1, 2, 3];
let mut dst = [0; 5];
Expand All @@ -1469,6 +1485,7 @@ fn test_copy_from_slice_dst_longer() {

#[test]
#[should_panic(expected = "destination and source slices have different lengths")]
#[cfg(not(miri))] // Miri does not support panics
fn test_copy_from_slice_dst_shorter() {
let src = [0, 1, 2, 3];
let mut dst = [0; 3];
Expand Down Expand Up @@ -1588,6 +1605,7 @@ thread_local!(static SILENCE_PANIC: Cell<bool> = Cell::new(false));

#[test]
#[cfg_attr(target_os = "emscripten", ignore)] // no threads
#[cfg(not(miri))] // Miri does not support panics
fn panic_safe() {
let prev = panic::take_hook();
panic::set_hook(Box::new(move |info| {
Expand Down
12 changes: 12 additions & 0 deletions src/liballoc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ fn test_vec_truncate_drop() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_vec_truncate_fail() {
struct BadElem(i32);
impl Drop for BadElem {
Expand All @@ -391,48 +392,55 @@ fn test_index() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_index_out_of_bounds() {
let vec = vec![1, 2, 3];
let _ = vec[3];
}

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_slice_out_of_bounds_1() {
let x = vec![1, 2, 3, 4, 5];
&x[!0..];
}

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_slice_out_of_bounds_2() {
let x = vec![1, 2, 3, 4, 5];
&x[..6];
}

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_slice_out_of_bounds_3() {
let x = vec![1, 2, 3, 4, 5];
&x[!0..4];
}

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_slice_out_of_bounds_4() {
let x = vec![1, 2, 3, 4, 5];
&x[1..6];
}

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_slice_out_of_bounds_5() {
let x = vec![1, 2, 3, 4, 5];
&x[3..2];
}

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_swap_remove_empty() {
let mut vec = Vec::<i32>::new();
vec.swap_remove(0);
Expand Down Expand Up @@ -503,6 +511,7 @@ fn test_drain_items_zero_sized() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_drain_out_of_bounds() {
let mut v = vec![1, 2, 3, 4, 5];
v.drain(5..6);
Expand Down Expand Up @@ -576,6 +585,7 @@ fn test_drain_max_vec_size() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_drain_inclusive_out_of_bounds() {
let mut v = vec![1, 2, 3, 4, 5];
v.drain(5..=5);
Expand Down Expand Up @@ -605,6 +615,7 @@ fn test_splice_inclusive_range() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_splice_out_of_bounds() {
let mut v = vec![1, 2, 3, 4, 5];
let a = [10, 11, 12];
Expand All @@ -613,6 +624,7 @@ fn test_splice_out_of_bounds() {

#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_splice_inclusive_out_of_bounds() {
let mut v = vec![1, 2, 3, 4, 5];
let a = [10, 11, 12];
Expand Down

0 comments on commit 767dadf

Please sign in to comment.