3 // ignore-wasm32-bare no unwinding panic
4 // ignore-avr no unwinding panic
5 // ignore-nvptx64 no unwinding panic
7 static mut CHECK: usize = 0;
9 struct DropChecker(usize);
11 impl Drop for DropChecker {
14 if CHECK != self.0 - 1 {
15 panic!("Found {}, should have found {}", CHECK, self.0 - 1);
22 macro_rules! check_drops {
24 unsafe { assert_eq!(CHECK, $l) }
30 impl Drop for DropPanic {
38 let foo = DropChecker(1);
39 let v: [DropChecker; 0] = [foo; 0];
47 let foo = DropChecker(1);
48 let v: [DropChecker; 1] = [foo; 1];
54 const DROP_CHECKER: DropChecker = DropChecker(1);
58 let v: [DropChecker; 0] = [DROP_CHECKER; 0];
66 let v: [DropChecker; 1] = [DROP_CHECKER; 1];
72 fn const_generic_zero<const N: usize>() {
74 let v: [DropChecker; N] = [DROP_CHECKER; N];
80 fn const_generic_one<const N: usize>() {
82 let v: [DropChecker; N] = [DROP_CHECKER; N];
88 // Make sure that things are allowed to promote as expected
92 let foo = DropChecker(1);
93 let v: &'static [DropChecker; 0] = &[foo; 0];
99 // Verify that unwinding in the drop causes the right things to drop in the right order
101 unsafe { CHECK = 0 };
102 std::panic::catch_unwind(|| {
103 let panic = DropPanic;
104 let _local = DropChecker(2);
105 let _v = (DropChecker(1), [panic; 0]);
106 std::process::abort();
117 const_generic_zero::<0>();
118 const_generic_one::<1>();