Skip to content

Commit e775820

Browse files
authored
Rollup merge of #67119 - RalfJung:miri-test-libstd, r=alexcrichton
libstd miri tests: avoid warnings Ignore tests in a way that all the code still gets compiled, to get rid of all the "unused" warnings that otherwise show up when running the test suite in Miri.
2 parents a0e00f8 + ab73d10 commit e775820

File tree

16 files changed

+48
-42
lines changed

16 files changed

+48
-42
lines changed

src/liballoc/alloc/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn allocate_zeroed() {
2222
}
2323

2424
#[bench]
25-
#[cfg(not(miri))] // Miri does not support benchmarks
25+
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
2626
fn alloc_owned_small(b: &mut Bencher) {
2727
b.iter(|| {
2828
let _: Box<_> = box 10;

src/liballoc/collections/linked_list/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn test_insert_prev() {
182182

183183
#[test]
184184
#[cfg_attr(target_os = "emscripten", ignore)]
185-
#[cfg(not(miri))] // Miri does not support threads
185+
#[cfg_attr(miri, ignore)] // Miri does not support threads
186186
fn test_send() {
187187
let n = list_from(&[1, 2, 3]);
188188
thread::spawn(move || {

src/liballoc/collections/vec_deque/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::*;
33
use ::test;
44

55
#[bench]
6-
#[cfg(not(miri))] // Miri does not support benchmarks
6+
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
77
fn bench_push_back_100(b: &mut test::Bencher) {
88
let mut deq = VecDeque::with_capacity(101);
99
b.iter(|| {
@@ -16,7 +16,7 @@ fn bench_push_back_100(b: &mut test::Bencher) {
1616
}
1717

1818
#[bench]
19-
#[cfg(not(miri))] // Miri does not support benchmarks
19+
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
2020
fn bench_push_front_100(b: &mut test::Bencher) {
2121
let mut deq = VecDeque::with_capacity(101);
2222
b.iter(|| {
@@ -29,7 +29,7 @@ fn bench_push_front_100(b: &mut test::Bencher) {
2929
}
3030

3131
#[bench]
32-
#[cfg(not(miri))] // Miri does not support benchmarks
32+
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
3333
fn bench_pop_back_100(b: &mut test::Bencher) {
3434
let mut deq = VecDeque::<i32>::with_capacity(101);
3535

@@ -43,7 +43,7 @@ fn bench_pop_back_100(b: &mut test::Bencher) {
4343
}
4444

4545
#[bench]
46-
#[cfg(not(miri))] // Miri does not support benchmarks
46+
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
4747
fn bench_pop_front_100(b: &mut test::Bencher) {
4848
let mut deq = VecDeque::<i32>::with_capacity(101);
4949

src/liballoc/sync/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Drop for Canary {
2929

3030
#[test]
3131
#[cfg_attr(target_os = "emscripten", ignore)]
32-
#[cfg(not(miri))] // Miri does not support threads
32+
#[cfg_attr(miri, ignore)] // Miri does not support threads
3333
fn manually_share_arc() {
3434
let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
3535
let arc_v = Arc::new(v);
@@ -334,7 +334,7 @@ fn test_ptr_eq() {
334334

335335
#[test]
336336
#[cfg_attr(target_os = "emscripten", ignore)]
337-
#[cfg(not(miri))] // Miri does not support threads
337+
#[cfg_attr(miri, ignore)] // Miri does not support threads
338338
fn test_weak_count_locked() {
339339
let mut a = Arc::new(atomic::AtomicBool::new(false));
340340
let a2 = a.clone();

src/liballoc/tests/slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ fn test_reverse() {
388388
}
389389

390390
#[test]
391-
#[cfg(not(miri))] // Miri is too slow
391+
#[cfg_attr(miri, ignore)] // Miri is too slow
392392
fn test_sort() {
393393
let mut rng = thread_rng();
394394

@@ -1610,7 +1610,7 @@ fn panic_safe() {
16101610
let moduli = &[5, 20, 50];
16111611

16121612
#[cfg(miri)]
1613-
let lens = (1..13);
1613+
let lens = 1..13;
16141614
#[cfg(miri)]
16151615
let moduli = &[10];
16161616

src/liballoc/tests/str.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn test_join_for_different_lengths_with_long_separator() {
166166
}
167167

168168
#[test]
169-
#[cfg(not(miri))] // Miri is too slow
169+
#[cfg_attr(miri, ignore)] // Miri is too slow
170170
fn test_unsafe_slice() {
171171
assert_eq!("ab", unsafe {"abc".get_unchecked(0..2)});
172172
assert_eq!("bc", unsafe {"abc".get_unchecked(1..3)});
@@ -483,8 +483,8 @@ mod slice_index {
483483
}
484484

485485
#[test]
486-
#[cfg(not(target_os = "emscripten"))] // hits an OOM
487-
#[cfg(not(miri))] // Miri is too slow
486+
#[cfg_attr(target_os = "emscripten", ignore)] // hits an OOM
487+
#[cfg_attr(miri, ignore)] // Miri is too slow
488488
fn simple_big() {
489489
fn a_million_letter_x() -> String {
490490
let mut i = 0;
@@ -1069,7 +1069,7 @@ fn test_rev_iterator() {
10691069
}
10701070

10711071
#[test]
1072-
#[cfg(not(miri))] // Miri is too slow
1072+
#[cfg_attr(miri, ignore)] // Miri is too slow
10731073
fn test_chars_decoding() {
10741074
let mut bytes = [0; 4];
10751075
for c in (0..0x110000).filter_map(std::char::from_u32) {
@@ -1081,7 +1081,7 @@ fn test_chars_decoding() {
10811081
}
10821082

10831083
#[test]
1084-
#[cfg(not(miri))] // Miri is too slow
1084+
#[cfg_attr(miri, ignore)] // Miri is too slow
10851085
fn test_chars_rev_decoding() {
10861086
let mut bytes = [0; 4];
10871087
for c in (0..0x110000).filter_map(std::char::from_u32) {
@@ -1380,7 +1380,6 @@ fn test_bool_from_str() {
13801380
assert_eq!("not even a boolean".parse::<bool>().ok(), None);
13811381
}
13821382

1383-
#[cfg(not(miri))] // Miri is too slow
13841383
fn check_contains_all_substrings(s: &str) {
13851384
assert!(s.contains(""));
13861385
for i in 0..s.len() {
@@ -1391,7 +1390,7 @@ fn check_contains_all_substrings(s: &str) {
13911390
}
13921391

13931392
#[test]
1394-
#[cfg(not(miri))] // Miri is too slow
1393+
#[cfg_attr(miri, ignore)] // Miri is too slow
13951394
fn strslice_issue_16589() {
13961395
assert!("bananas".contains("nana"));
13971396

@@ -1408,7 +1407,7 @@ fn strslice_issue_16878() {
14081407

14091408

14101409
#[test]
1411-
#[cfg(not(miri))] // Miri is too slow
1410+
#[cfg_attr(miri, ignore)] // Miri is too slow
14121411
fn test_strslice_contains() {
14131412
let x = "There are moments, Jeeves, when one asks oneself, 'Do trousers matter?'";
14141413
check_contains_all_substrings(x);

src/liballoc/tests/string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ fn test_reserve_exact() {
523523
}
524524

525525
#[test]
526-
#[cfg(not(miri))] // Miri does not support signalling OOM
526+
#[cfg_attr(miri, ignore)] // Miri does not support signalling OOM
527527
fn test_try_reserve() {
528528

529529
// These are the interesting cases:
@@ -601,7 +601,7 @@ fn test_try_reserve() {
601601
}
602602

603603
#[test]
604-
#[cfg(not(miri))] // Miri does not support signalling OOM
604+
#[cfg_attr(miri, ignore)] // Miri does not support signalling OOM
605605
fn test_try_reserve_exact() {
606606

607607
// This is exactly the same as test_try_reserve with the method changed.

src/liballoc/tests/vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ fn test_reserve_exact() {
10801080
}
10811081

10821082
#[test]
1083-
#[cfg(not(miri))] // Miri does not support signalling OOM
1083+
#[cfg_attr(miri, ignore)] // Miri does not support signalling OOM
10841084
fn test_try_reserve() {
10851085

10861086
// These are the interesting cases:
@@ -1183,7 +1183,7 @@ fn test_try_reserve() {
11831183
}
11841184

11851185
#[test]
1186-
#[cfg(not(miri))] // Miri does not support signalling OOM
1186+
#[cfg_attr(miri, ignore)] // Miri does not support signalling OOM
11871187
fn test_try_reserve_exact() {
11881188

11891189
// This is exactly the same as test_try_reserve with the method changed.

src/liballoc/tests/vec_deque.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ fn test_reserve_exact_2() {
11001100
}
11011101

11021102
#[test]
1103-
#[cfg(not(miri))] // Miri does not support signalling OOM
1103+
#[cfg_attr(miri, ignore)] // Miri does not support signalling OOM
11041104
fn test_try_reserve() {
11051105
// These are the interesting cases:
11061106
// * exactly isize::MAX should never trigger a CapacityOverflow (can be OOM)
@@ -1214,7 +1214,7 @@ fn test_try_reserve() {
12141214
}
12151215

12161216
#[test]
1217-
#[cfg(not(miri))] // Miri does not support signalling OOM
1217+
#[cfg_attr(miri, ignore)] // Miri does not support signalling OOM
12181218
fn test_try_reserve_exact() {
12191219
// This is exactly the same as test_try_reserve with the method changed.
12201220
// See that test for comments.

src/libcore/tests/hash/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,16 @@ fn test_writer_hasher() {
7171
let ptr = 5_usize as *mut i32;
7272
assert_eq!(hash(&ptr), 5);
7373

74+
if cfg!(miri) { // Miri cannot hash pointers
75+
return;
76+
}
77+
7478
let cs: &mut [u8] = &mut [1, 2, 3];
7579
let ptr = cs.as_ptr();
7680
let slice_ptr = cs as *const [u8];
77-
#[cfg(not(miri))] // Miri cannot hash pointers
7881
assert_eq!(hash(&slice_ptr), hash(&ptr) + cs.len() as u64);
7982

8083
let slice_ptr = cs as *mut [u8];
81-
#[cfg(not(miri))] // Miri cannot hash pointers
8284
assert_eq!(hash(&slice_ptr), hash(&ptr) + cs.len() as u64);
8385
}
8486

src/libcore/tests/num/dec2flt/mod.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ fn ordinary() {
3131
test_literal!(0.1);
3232
test_literal!(12345.);
3333
test_literal!(0.9999999);
34-
#[cfg(not(miri))] // Miri is too slow
34+
35+
if cfg!(miri) { // Miri is too slow
36+
return;
37+
}
38+
3539
test_literal!(2.2250738585072014e-308);
3640
}
3741

@@ -53,7 +57,7 @@ fn large() {
5357
}
5458

5559
#[test]
56-
#[cfg(not(miri))] // Miri is too slow
60+
#[cfg_attr(miri, ignore)] // Miri is too slow
5761
fn subnormals() {
5862
test_literal!(5e-324);
5963
test_literal!(91e-324);
@@ -65,7 +69,7 @@ fn subnormals() {
6569
}
6670

6771
#[test]
68-
#[cfg(not(miri))] // Miri is too slow
72+
#[cfg_attr(miri, ignore)] // Miri is too slow
6973
fn infinity() {
7074
test_literal!(1e400);
7175
test_literal!(1e309);
@@ -77,9 +81,12 @@ fn infinity() {
7781
fn zero() {
7882
test_literal!(0.0);
7983
test_literal!(1e-325);
80-
#[cfg(not(miri))] // Miri is too slow
84+
85+
if cfg!(miri) { // Miri is too slow
86+
return;
87+
}
88+
8189
test_literal!(1e-326);
82-
#[cfg(not(miri))] // Miri is too slow
8390
test_literal!(1e-500);
8491
}
8592

src/libcore/tests/num/flt2dec/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ pub fn f32_shortest_sanity_test<F>(mut f: F) where F: FnMut(&Decoded, &mut [u8])
256256
check_shortest!(f(minf32) => b"1", -44);
257257
}
258258

259-
#[cfg(not(miri))] // Miri is too slow
260259
pub fn f32_exact_sanity_test<F>(mut f: F)
261260
where F: FnMut(&Decoded, &mut [u8], i16) -> (usize, i16) {
262261
let minf32 = ldexp_f32(1.0, -149);
@@ -362,7 +361,6 @@ pub fn f64_shortest_sanity_test<F>(mut f: F) where F: FnMut(&Decoded, &mut [u8])
362361
check_shortest!(f(minf64) => b"5", -323);
363362
}
364363

365-
#[cfg(not(miri))] // Miri is too slow
366364
pub fn f64_exact_sanity_test<F>(mut f: F)
367365
where F: FnMut(&Decoded, &mut [u8], i16) -> (usize, i16) {
368366
let minf64 = ldexp_f64(1.0, -1074);

src/libcore/tests/num/flt2dec/strategy/dragon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn shortest_sanity_test() {
2222
}
2323

2424
#[test]
25-
#[cfg(not(miri))] // Miri is too slow
25+
#[cfg_attr(miri, ignore)] // Miri is too slow
2626
fn exact_sanity_test() {
2727
// This test ends up running what I can only assume is some corner-ish case
2828
// of the `exp2` library function, defined in whatever C runtime we're

src/libcore/tests/num/flt2dec/strategy/grisu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn shortest_sanity_test() {
4141
}
4242

4343
#[test]
44-
#[cfg(not(miri))] // Miri is too slow
44+
#[cfg_attr(miri, ignore)] // Miri is too slow
4545
fn exact_sanity_test() {
4646
// See comments in dragon.rs's exact_sanity_test for why this test is
4747
// ignored on MSVC

src/libcore/tests/ptr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ fn write_unaligned_drop() {
289289
}
290290

291291
#[test]
292-
#[cfg(not(miri))] // Miri does not compute a maximal `mid` for `align_offset`
292+
#[cfg_attr(miri, ignore)] // Miri does not compute a maximal `mid` for `align_offset`
293293
fn align_offset_zst() {
294294
// For pointers of stride = 0, the pointer is already aligned or it cannot be aligned at
295295
// all, because no amount of elements will align the pointer.
@@ -304,7 +304,7 @@ fn align_offset_zst() {
304304
}
305305

306306
#[test]
307-
#[cfg(not(miri))] // Miri does not compute a maximal `mid` for `align_offset`
307+
#[cfg_attr(miri, ignore)] // Miri does not compute a maximal `mid` for `align_offset`
308308
fn align_offset_stride1() {
309309
// For pointers of stride = 1, the pointer can always be aligned. The offset is equal to
310310
// number of bytes.
@@ -326,7 +326,7 @@ fn align_offset_stride1() {
326326
}
327327

328328
#[test]
329-
#[cfg(not(miri))] // Miri is too slow
329+
#[cfg_attr(miri, ignore)] // Miri is too slow
330330
fn align_offset_weird_strides() {
331331
#[repr(packed)]
332332
struct A3(u16, u8);

src/libcore/tests/slice.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ fn test_rotate_right() {
11831183
}
11841184

11851185
#[test]
1186-
#[cfg(not(miri))] // Miri is too slow
1186+
#[cfg_attr(miri, ignore)] // Miri is too slow
11871187
fn brute_force_rotate_test_0() {
11881188
// In case of edge cases involving multiple algorithms
11891189
let n = 300;
@@ -1302,7 +1302,7 @@ fn sort_unstable() {
13021302

13031303
#[test]
13041304
#[cfg(not(target_arch = "wasm32"))]
1305-
#[cfg(not(miri))] // Miri is too slow
1305+
#[cfg_attr(miri, ignore)] // Miri is too slow
13061306
fn partition_at_index() {
13071307
use core::cmp::Ordering::{Equal, Greater, Less};
13081308
use rand::rngs::StdRng;
@@ -1505,7 +1505,7 @@ pub mod memchr {
15051505
}
15061506

15071507
#[test]
1508-
#[cfg(not(miri))] // Miri does not compute a maximal `mid` for `align_offset`
1508+
#[cfg_attr(miri, ignore)] // Miri does not compute a maximal `mid` for `align_offset`
15091509
fn test_align_to_simple() {
15101510
let bytes = [1u8, 2, 3, 4, 5, 6, 7];
15111511
let (prefix, aligned, suffix) = unsafe { bytes.align_to::<u16>() };
@@ -1535,7 +1535,7 @@ fn test_align_to_zst() {
15351535
}
15361536

15371537
#[test]
1538-
#[cfg(not(miri))] // Miri does not compute a maximal `mid` for `align_offset`
1538+
#[cfg_attr(miri, ignore)] // Miri does not compute a maximal `mid` for `align_offset`
15391539
fn test_align_to_non_trivial() {
15401540
#[repr(align(8))]
15411541
struct U64(u64, u64);

0 commit comments

Comments
 (0)