Skip to content

Commit 178becd

Browse files
committed
Auto merge of #48549 - alexcrichton:update-cargo, r=Mark-Simulacrum
Update Cargo submodule Hopefully a routine update...
2 parents 6c70cd1 + 994bfd4 commit 178becd

File tree

17 files changed

+675
-743
lines changed

17 files changed

+675
-743
lines changed

src/Cargo.lock

+341-361
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/builder.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,9 @@ impl<'a> Builder<'a> {
759759
// be resolved because MinGW has the import library. The downside is we
760760
// don't get newer functions from Windows, but we don't use any of them
761761
// anyway.
762-
cargo.env("WINAPI_NO_BUNDLED_LIBRARIES", "1");
762+
if mode != Mode::Tool {
763+
cargo.env("WINAPI_NO_BUNDLED_LIBRARIES", "1");
764+
}
763765

764766
if self.is_very_verbose() {
765767
cargo.arg("-v");

src/liballoc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ core = { path = "../libcore" }
1212
std_unicode = { path = "../libstd_unicode" }
1313

1414
[dev-dependencies]
15-
rand = "0.3"
15+
rand = "0.4"
1616

1717
[[test]]
1818
name = "collectionstests"

src/liballoc/tests/binary_heap.rs

+82-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::panic;
11+
use std::cmp;
1212
use std::collections::BinaryHeap;
1313
use std::collections::binary_heap::{Drain, PeekMut};
14+
use std::panic::{self, AssertUnwindSafe};
15+
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
16+
17+
use rand::{thread_rng, Rng};
1418

1519
#[test]
1620
fn test_iterator() {
@@ -300,3 +304,80 @@ fn assert_covariance() {
300304
d
301305
}
302306
}
307+
308+
// old binaryheap failed this test
309+
//
310+
// Integrity means that all elements are present after a comparison panics,
311+
// even if the order may not be correct.
312+
//
313+
// Destructors must be called exactly once per element.
314+
#[test]
315+
fn panic_safe() {
316+
static DROP_COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;
317+
318+
#[derive(Eq, PartialEq, Ord, Clone, Debug)]
319+
struct PanicOrd<T>(T, bool);
320+
321+
impl<T> Drop for PanicOrd<T> {
322+
fn drop(&mut self) {
323+
// update global drop count
324+
DROP_COUNTER.fetch_add(1, Ordering::SeqCst);
325+
}
326+
}
327+
328+
impl<T: PartialOrd> PartialOrd for PanicOrd<T> {
329+
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
330+
if self.1 || other.1 {
331+
panic!("Panicking comparison");
332+
}
333+
self.0.partial_cmp(&other.0)
334+
}
335+
}
336+
let mut rng = thread_rng();
337+
const DATASZ: usize = 32;
338+
const NTEST: usize = 10;
339+
340+
// don't use 0 in the data -- we want to catch the zeroed-out case.
341+
let data = (1..DATASZ + 1).collect::<Vec<_>>();
342+
343+
// since it's a fuzzy test, run several tries.
344+
for _ in 0..NTEST {
345+
for i in 1..DATASZ + 1 {
346+
DROP_COUNTER.store(0, Ordering::SeqCst);
347+
348+
let mut panic_ords: Vec<_> = data.iter()
349+
.filter(|&&x| x != i)
350+
.map(|&x| PanicOrd(x, false))
351+
.collect();
352+
let panic_item = PanicOrd(i, true);
353+
354+
// heapify the sane items
355+
rng.shuffle(&mut panic_ords);
356+
let mut heap = BinaryHeap::from(panic_ords);
357+
let inner_data;
358+
359+
{
360+
// push the panicking item to the heap and catch the panic
361+
let thread_result = {
362+
let mut heap_ref = AssertUnwindSafe(&mut heap);
363+
panic::catch_unwind(move || {
364+
heap_ref.push(panic_item);
365+
})
366+
};
367+
assert!(thread_result.is_err());
368+
369+
// Assert no elements were dropped
370+
let drops = DROP_COUNTER.load(Ordering::SeqCst);
371+
assert!(drops == 0, "Must not drop items. drops={}", drops);
372+
inner_data = heap.clone().into_vec();
373+
drop(heap);
374+
}
375+
let drops = DROP_COUNTER.load(Ordering::SeqCst);
376+
assert_eq!(drops, DATASZ);
377+
378+
let mut data_sorted = inner_data.into_iter().map(|p| p.0).collect::<Vec<_>>();
379+
data_sorted.sort();
380+
assert_eq!(data_sorted, data);
381+
}
382+
}
383+
}

src/liballoc/tests/slice.rs

+165
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use std::cell::Cell;
1112
use std::cmp::Ordering::{Equal, Greater, Less};
13+
use std::cmp::Ordering;
1214
use std::mem;
15+
use std::panic;
1316
use std::rc::Rc;
17+
use std::sync::atomic::Ordering::Relaxed;
18+
use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize};
19+
use std::thread;
1420

1521
use rand::{Rng, thread_rng};
1622

@@ -1341,3 +1347,162 @@ fn test_copy_from_slice_dst_shorter() {
13411347
let mut dst = [0; 3];
13421348
dst.copy_from_slice(&src);
13431349
}
1350+
1351+
const MAX_LEN: usize = 80;
1352+
1353+
static DROP_COUNTS: [AtomicUsize; MAX_LEN] = [
1354+
// FIXME #5244: AtomicUsize is not Copy.
1355+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1356+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1357+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1358+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1359+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1360+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1361+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1362+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1363+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1364+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1365+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1366+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1367+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1368+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1369+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1370+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1371+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1372+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1373+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1374+
AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
1375+
];
1376+
1377+
static VERSIONS: AtomicUsize = ATOMIC_USIZE_INIT;
1378+
1379+
#[derive(Clone, Eq)]
1380+
struct DropCounter {
1381+
x: u32,
1382+
id: usize,
1383+
version: Cell<usize>,
1384+
}
1385+
1386+
impl PartialEq for DropCounter {
1387+
fn eq(&self, other: &Self) -> bool {
1388+
self.partial_cmp(other) == Some(Ordering::Equal)
1389+
}
1390+
}
1391+
1392+
impl PartialOrd for DropCounter {
1393+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
1394+
self.version.set(self.version.get() + 1);
1395+
other.version.set(other.version.get() + 1);
1396+
VERSIONS.fetch_add(2, Relaxed);
1397+
self.x.partial_cmp(&other.x)
1398+
}
1399+
}
1400+
1401+
impl Ord for DropCounter {
1402+
fn cmp(&self, other: &Self) -> Ordering {
1403+
self.partial_cmp(other).unwrap()
1404+
}
1405+
}
1406+
1407+
impl Drop for DropCounter {
1408+
fn drop(&mut self) {
1409+
DROP_COUNTS[self.id].fetch_add(1, Relaxed);
1410+
VERSIONS.fetch_sub(self.version.get(), Relaxed);
1411+
}
1412+
}
1413+
1414+
macro_rules! test {
1415+
($input:ident, $func:ident) => {
1416+
let len = $input.len();
1417+
1418+
// Work out the total number of comparisons required to sort
1419+
// this array...
1420+
let mut count = 0usize;
1421+
$input.to_owned().$func(|a, b| { count += 1; a.cmp(b) });
1422+
1423+
// ... and then panic on each and every single one.
1424+
for panic_countdown in 0..count {
1425+
// Refresh the counters.
1426+
VERSIONS.store(0, Relaxed);
1427+
for i in 0..len {
1428+
DROP_COUNTS[i].store(0, Relaxed);
1429+
}
1430+
1431+
let v = $input.to_owned();
1432+
let _ = thread::spawn(move || {
1433+
let mut v = v;
1434+
let mut panic_countdown = panic_countdown;
1435+
v.$func(|a, b| {
1436+
if panic_countdown == 0 {
1437+
SILENCE_PANIC.with(|s| s.set(true));
1438+
panic!();
1439+
}
1440+
panic_countdown -= 1;
1441+
a.cmp(b)
1442+
})
1443+
}).join();
1444+
1445+
// Check that the number of things dropped is exactly
1446+
// what we expect (i.e. the contents of `v`).
1447+
for (i, c) in DROP_COUNTS.iter().enumerate().take(len) {
1448+
let count = c.load(Relaxed);
1449+
assert!(count == 1,
1450+
"found drop count == {} for i == {}, len == {}",
1451+
count, i, len);
1452+
}
1453+
1454+
// Check that the most recent versions of values were dropped.
1455+
assert_eq!(VERSIONS.load(Relaxed), 0);
1456+
}
1457+
}
1458+
}
1459+
1460+
thread_local!(static SILENCE_PANIC: Cell<bool> = Cell::new(false));
1461+
1462+
#[test]
1463+
#[cfg_attr(target_os = "emscripten", ignore)] // no threads
1464+
fn panic_safe() {
1465+
let prev = panic::take_hook();
1466+
panic::set_hook(Box::new(move |info| {
1467+
if !SILENCE_PANIC.with(|s| s.get()) {
1468+
prev(info);
1469+
}
1470+
}));
1471+
1472+
let mut rng = thread_rng();
1473+
1474+
for len in (1..20).chain(70..MAX_LEN) {
1475+
for &modulus in &[5, 20, 50] {
1476+
for &has_runs in &[false, true] {
1477+
let mut input = (0..len)
1478+
.map(|id| {
1479+
DropCounter {
1480+
x: rng.next_u32() % modulus,
1481+
id: id,
1482+
version: Cell::new(0),
1483+
}
1484+
})
1485+
.collect::<Vec<_>>();
1486+
1487+
if has_runs {
1488+
for c in &mut input {
1489+
c.x = c.id as u32;
1490+
}
1491+
1492+
for _ in 0..5 {
1493+
let a = rng.gen::<usize>() % len;
1494+
let b = rng.gen::<usize>() % len;
1495+
if a < b {
1496+
input[a..b].reverse();
1497+
} else {
1498+
input.swap(a, b);
1499+
}
1500+
}
1501+
}
1502+
1503+
test!(input, sort_by);
1504+
test!(input, sort_unstable_by);
1505+
}
1506+
}
1507+
}
1508+
}

src/libcore/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ path = "../libcore/tests/lib.rs"
1616
[[bench]]
1717
name = "corebenches"
1818
path = "../libcore/benches/lib.rs"
19+
20+
[dev-dependencies]
21+
rand = "0.4"

src/libcore/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
extern crate core;
5252
extern crate test;
53+
extern crate rand;
5354

5455
mod any;
5556
mod array;

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

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ mod strategy {
2323
mod dragon;
2424
mod grisu;
2525
}
26+
mod random;
2627

2728
pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
2829
match decode(v).1 {

src/test/run-pass-fulldeps/flt2dec.rs renamed to src/libcore/tests/num/flt2dec/random.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags:--test
12-
13-
#![feature(rustc_private, flt2dec)]
14-
15-
extern crate core;
16-
extern crate rand;
11+
#![cfg(not(target_arch = "wasm32"))]
1712

1813
use std::i16;
1914
use std::mem;
@@ -24,8 +19,9 @@ use core::num::flt2dec::strategy::grisu::format_exact_opt;
2419
use core::num::flt2dec::strategy::grisu::format_shortest_opt;
2520
use core::num::flt2dec::{decode, DecodableFloat, FullDecoded, Decoded};
2621

27-
use rand::{Rand, XorShiftRng};
22+
use rand::{self, Rand, XorShiftRng};
2823
use rand::distributions::{IndependentSample, Range};
24+
2925
pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
3026
match decode(v).1 {
3127
FullDecoded::Finite(decoded) => decoded,
@@ -161,3 +157,4 @@ fn exact_f64_random_equivalence_test() {
161157
|d, buf| fallback(d, buf, i16::MIN), k, 1_000);
162158
}
163159
}
160+

0 commit comments

Comments
 (0)