]>
Commit | Line | Data |
---|---|---|
416331ca XL |
1 | // run-pass |
2 | ||
0bf4aa26 XL |
3 | #![allow(unused_must_use)] |
4 | #![allow(dead_code)] | |
5 | #![allow(unused_variables)] | |
1a4d82fc JJ |
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 | ||
7453a54e | 22 | // ignore-emscripten no threads support |
c34b1796 | 23 | |
1a4d82fc JJ |
24 | #![feature(box_syntax)] |
25 | ||
85aaf69f | 26 | use std::thread; |
1a4d82fc JJ |
27 | |
28 | enum Conzabble { | |
29 | Bickwick(Foo) | |
30 | } | |
31 | ||
c34b1796 | 32 | struct Foo { field: Box<usize> } |
1a4d82fc | 33 | |
c34b1796 | 34 | fn do_it(x: &[usize]) -> Foo { |
1a4d82fc JJ |
35 | panic!() |
36 | } | |
37 | ||
c30ab7b3 | 38 | fn get_bar(x: usize) -> Vec<usize> { vec![x * 2] } |
1a4d82fc JJ |
39 | |
40 | pub fn fails() { | |
41 | let x = 2; | |
c34b1796 | 42 | let mut y: Vec<Box<_>> = Vec::new(); |
85aaf69f | 43 | y.push(box Conzabble::Bickwick(do_it(&get_bar(x)))); |
1a4d82fc JJ |
44 | } |
45 | ||
46 | pub fn main() { | |
85aaf69f | 47 | thread::spawn(fails).join(); |
1a4d82fc | 48 | } |