]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | // Test cleanup of rvalue temporary that occurs while `box` construction | |
12 | // is in progress. This scenario revealed a rather terrible bug. The | |
13 | // ingredients are: | |
14 | // | |
15 | // 1. Partial cleanup of `box` is in scope, | |
16 | // 2. cleanup of return value from `get_bar()` is in scope, | |
17 | // 3. do_it() panics. | |
18 | // | |
19 | // This led to a bug because `the top-most frame that was to be | |
20 | // cleaned (which happens to be the partial cleanup of `box`) required | |
21 | // multiple basic blocks, which led to us dropping part of the cleanup | |
22 | // from the top-most frame. | |
23 | // | |
24 | // It's unclear how likely such a bug is to recur, but it seems like a | |
25 | // scenario worth testing. | |
26 | ||
7453a54e | 27 | // ignore-emscripten no threads support |
c34b1796 | 28 | |
1a4d82fc JJ |
29 | #![allow(unknown_features)] |
30 | #![feature(box_syntax)] | |
31 | ||
85aaf69f | 32 | use std::thread; |
1a4d82fc JJ |
33 | |
34 | enum Conzabble { | |
35 | Bickwick(Foo) | |
36 | } | |
37 | ||
c34b1796 | 38 | struct Foo { field: Box<usize> } |
1a4d82fc | 39 | |
c34b1796 | 40 | fn do_it(x: &[usize]) -> Foo { |
1a4d82fc JJ |
41 | panic!() |
42 | } | |
43 | ||
c30ab7b3 | 44 | fn get_bar(x: usize) -> Vec<usize> { vec![x * 2] } |
1a4d82fc JJ |
45 | |
46 | pub fn fails() { | |
47 | let x = 2; | |
c34b1796 | 48 | let mut y: Vec<Box<_>> = Vec::new(); |
85aaf69f | 49 | y.push(box Conzabble::Bickwick(do_it(&get_bar(x)))); |
1a4d82fc JJ |
50 | } |
51 | ||
52 | pub fn main() { | |
85aaf69f | 53 | thread::spawn(fails).join(); |
1a4d82fc | 54 | } |