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