2019-07-26 21:54:25 +00:00
|
|
|
// run-pass
|
|
|
|
|
2018-09-14 10:20:28 +00:00
|
|
|
#![allow(unused_must_use)]
|
|
|
|
#![allow(dead_code)]
|
|
|
|
#![allow(unused_variables)]
|
2014-05-06 01:56:44 +00:00
|
|
|
// Test cleanup of rvalue temporary that occurs while `box` construction
|
2014-01-15 19:39:08 +00:00
|
|
|
// is in progress. This scenario revealed a rather terrible bug. The
|
|
|
|
// ingredients are:
|
|
|
|
//
|
2014-05-06 01:56:44 +00:00
|
|
|
// 1. Partial cleanup of `box` is in scope,
|
2014-01-15 19:39:08 +00:00
|
|
|
// 2. cleanup of return value from `get_bar()` is in scope,
|
2014-10-09 19:17:22 +00:00
|
|
|
// 3. do_it() panics.
|
2014-01-15 19:39:08 +00:00
|
|
|
//
|
|
|
|
// This led to a bug because `the top-most frame that was to be
|
2014-05-06 01:56:44 +00:00
|
|
|
// cleaned (which happens to be the partial cleanup of `box`) required
|
2014-01-15 19:39:08 +00:00
|
|
|
// multiple basic blocks, which led to us dropping part of the cleanup
|
|
|
|
// from the top-most frame.
|
|
|
|
//
|
|
|
|
// It's unclear how likely such a bug is to recur, but it seems like a
|
|
|
|
// scenario worth testing.
|
|
|
|
|
2016-02-11 11:34:41 +00:00
|
|
|
// ignore-emscripten no threads support
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2015-02-17 23:24:34 +00:00
|
|
|
use std::thread;
|
2014-01-15 19:39:08 +00:00
|
|
|
|
|
|
|
enum Conzabble {
|
|
|
|
Bickwick(Foo)
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
struct Foo { field: Box<usize> }
|
2014-01-15 19:39:08 +00:00
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn do_it(x: &[usize]) -> Foo {
|
2014-10-09 19:17:22 +00:00
|
|
|
panic!()
|
2014-01-15 19:39:08 +00:00
|
|
|
}
|
|
|
|
|
2016-10-29 21:54:04 +00:00
|
|
|
fn get_bar(x: usize) -> Vec<usize> { vec![x * 2] }
|
2014-01-15 19:39:08 +00:00
|
|
|
|
|
|
|
pub fn fails() {
|
|
|
|
let x = 2;
|
2015-02-17 20:41:32 +00:00
|
|
|
let mut y: Vec<Box<_>> = Vec::new();
|
2021-08-25 00:39:40 +00:00
|
|
|
y.push(Box::new(Conzabble::Bickwick(do_it(&get_bar(x)))));
|
2014-01-15 19:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2015-02-17 23:24:34 +00:00
|
|
|
thread::spawn(fails).join();
|
2014-01-15 19:39:08 +00:00
|
|
|
}
|