]> git.lizzy.rs Git - rust.git/blob - tests/ui/cleanup-rvalue-temp-during-incomplete-alloc.rs
Auto merge of #100178 - mati865:upgrade-mingw-w64-on-CI, r=nikic
[rust.git] / tests / ui / cleanup-rvalue-temp-during-incomplete-alloc.rs
1 // run-pass
2 // needs-unwind
3
4 #![allow(unused_must_use)]
5 #![allow(dead_code)]
6 #![allow(unused_variables)]
7 // Test cleanup of rvalue temporary that occurs while `box` construction
8 // is in progress. This scenario revealed a rather terrible bug.  The
9 // ingredients are:
10 //
11 // 1. Partial cleanup of `box` is in scope,
12 // 2. cleanup of return value from `get_bar()` is in scope,
13 // 3. do_it() panics.
14 //
15 // This led to a bug because `the top-most frame that was to be
16 // cleaned (which happens to be the partial cleanup of `box`) required
17 // multiple basic blocks, which led to us dropping part of the cleanup
18 // from the top-most frame.
19 //
20 // It's unclear how likely such a bug is to recur, but it seems like a
21 // scenario worth testing.
22
23 // ignore-emscripten no threads support
24
25 use std::thread;
26
27 enum Conzabble {
28     Bickwick(Foo)
29 }
30
31 struct Foo { field: Box<usize> }
32
33 fn do_it(x: &[usize]) -> Foo {
34     panic!()
35 }
36
37 fn get_bar(x: usize) -> Vec<usize> { vec![x * 2] }
38
39 pub fn fails() {
40     let x = 2;
41     let mut y: Vec<Box<_>> = Vec::new();
42     y.push(Box::new(Conzabble::Bickwick(do_it(&get_bar(x)))));
43 }
44
45 pub fn main() {
46     thread::spawn(fails).join();
47 }