2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2021-12-03 09:32:51 -06:00
|
|
|
// needs-unwind
|
2018-09-04 07:33:34 -05:00
|
|
|
#![allow(overflowing_literals)]
|
2018-08-30 07:18:55 -05:00
|
|
|
|
2016-02-11 05:34:41 -06:00
|
|
|
// ignore-emscripten no threads support
|
|
|
|
|
2015-03-10 19:25:53 -05:00
|
|
|
// Test that using the `vec!` macro nested within itself works when
|
|
|
|
// the contents implement Drop and we hit a panic in the middle of
|
|
|
|
// construction.
|
|
|
|
|
|
|
|
use std::thread;
|
2015-05-27 03:18:36 -05:00
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
2015-03-10 19:25:53 -05:00
|
|
|
|
2015-05-27 03:18:36 -05:00
|
|
|
static LOG: AtomicUsize = AtomicUsize::new(0);
|
2015-03-10 19:25:53 -05:00
|
|
|
|
|
|
|
struct D(u8);
|
|
|
|
|
|
|
|
impl Drop for D {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
println!("Dropping {}", self.0);
|
|
|
|
let old = LOG.load(Ordering::SeqCst);
|
2020-11-20 15:27:50 -06:00
|
|
|
let _ = LOG.compare_exchange(
|
|
|
|
old,
|
|
|
|
old << 4 | self.0 as usize,
|
|
|
|
Ordering::SeqCst,
|
|
|
|
Ordering::SeqCst,
|
|
|
|
);
|
2015-03-10 19:25:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
fn die() -> D { panic!("Oh no"); }
|
|
|
|
let g = thread::spawn(|| {
|
|
|
|
let _nested = vec![vec![D( 1), D( 2), D( 3), D( 4)],
|
|
|
|
vec![D( 5), D( 6), D( 7), D( 8)],
|
|
|
|
vec![D( 9), D(10), die(), D(12)],
|
|
|
|
vec![D(13), D(14), D(15), D(16)]];
|
|
|
|
});
|
|
|
|
assert!(g.join().is_err());
|
|
|
|
|
|
|
|
// When the panic occurs, we will be in the midst of constructing the
|
|
|
|
// second inner vector. Therefore, we drop the elements of the
|
|
|
|
// partially filled vector first, before we get around to dropping
|
|
|
|
// the elements of the filled vector.
|
|
|
|
|
|
|
|
// Issue 23222: The order in which the elements actually get
|
|
|
|
// dropped is a little funky: as noted above, we'll drop the 9+10
|
|
|
|
// first, but due to #23222, they get dropped in reverse
|
|
|
|
// order. Likewise, again due to #23222, we will drop the second
|
|
|
|
// filled vec before the first filled vec.
|
|
|
|
//
|
|
|
|
// If Issue 23222 is "fixed", then presumably the corrected
|
|
|
|
// expected order of events will be 0x__9_A__1_2_3_4__5_6_7_8;
|
|
|
|
// that is, we would still drop 9+10 first, since they belong to
|
|
|
|
// the more deeply nested expression when the panic occurs.
|
|
|
|
|
|
|
|
let expect = 0x__A_9__5_6_7_8__1_2_3_4;
|
|
|
|
let actual = LOG.load(Ordering::SeqCst);
|
|
|
|
assert!(actual == expect, "expect: 0x{:x} actual: 0x{:x}", expect, actual);
|
|
|
|
}
|