]> git.lizzy.rs Git - rust.git/blob - tests/ui/array-slice-vec/slice-panic-2.rs
Rollup merge of #106715 - BoxyUwU:new_solver_triagebot, r=lcnr
[rust.git] / tests / ui / array-slice-vec / slice-panic-2.rs
1 // run-pass
2 // needs-unwind
3
4 // ignore-emscripten no threads support
5
6 // Test that if a slicing expr[..] fails, the correct cleanups happen.
7
8
9 use std::thread;
10
11 struct Foo;
12
13 static mut DTOR_COUNT: isize = 0;
14
15 impl Drop for Foo {
16     fn drop(&mut self) { unsafe { DTOR_COUNT += 1; } }
17 }
18
19 fn bar() -> usize {
20     panic!();
21 }
22
23 fn foo() {
24     let x: &[_] = &[Foo, Foo];
25     let _ = &x[3..bar()];
26 }
27
28 fn main() {
29     let _ = thread::spawn(move|| foo()).join();
30     unsafe { assert_eq!(DTOR_COUNT, 2); }
31 }