Auto merge of #124032 - Voultapher:a-new-sort, r=thomcc · model-checking/verify-rust-std@9a945fd (original) (raw)

`@@ -34,7 +34,7 @@ macro_rules! do_test {

`

34

34

`}

`

35

35

``

36

36

`let v = $input.to_owned();

`

37

``

`-

let _ = std::panic::catch_unwind(move || {

`

``

37

`+

let _ = panic::catch_unwind(move || {

`

38

38

`let mut v = v;

`

39

39

`let mut panic_countdown = panic_countdown;

`

40

40

` v.$func(|a, b| {

`

`@@ -294,15 +294,20 @@ fn test_sort() {

`

294

294

`}

`

295

295

`}

`

296

296

``

297

``

`-

// Sort using a completely random comparison function.

`

298

``

`-

// This will reorder the elements somehow, but won't panic.

`

299

``

`-

let mut v = [0; 500];

`

300

``

`-

for i in 0..v.len() {

`

``

297

`+

const ORD_VIOLATION_MAX_LEN: usize = 500;

`

``

298

`+

let mut v = [0; ORD_VIOLATION_MAX_LEN];

`

``

299

`+

for i in 0..ORD_VIOLATION_MAX_LEN {

`

301

300

` v[i] = i as i32;

`

302

301

`}

`

303

``

`-

v.sort_by(|_, _| *[Less, Equal, Greater].choose(&mut rng).unwrap());

`

``

302

+

``

303

`+

// Sort using a completely random comparison function. This will reorder the elements somehow,

`

``

304

`+

// it may panic but the original elements must still be present.

`

``

305

`+

let _ = panic::catch_unwind(move || {

`

``

306

`+

v.sort_by(|_, _| *[Less, Equal, Greater].choose(&mut rng).unwrap());

`

``

307

`+

});

`

``

308

+

304

309

` v.sort();

`

305

``

`-

for i in 0..v.len() {

`

``

310

`+

for i in 0..ORD_VIOLATION_MAX_LEN {

`

306

311

`assert_eq!(v[i], i as i32);

`

307

312

`}

`

308

313

``