2014-02-05 16:33:10 -06:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-05-05 20:56:44 -05:00
|
|
|
// Test cleanup of rvalue temporary that occurs while `box` construction
|
2014-01-15 13:39:08 -06:00
|
|
|
// is in progress. This scenario revealed a rather terrible bug. The
|
|
|
|
// ingredients are:
|
|
|
|
//
|
2014-05-05 20:56:44 -05:00
|
|
|
// 1. Partial cleanup of `box` is in scope,
|
2014-01-15 13:39:08 -06:00
|
|
|
// 2. cleanup of return value from `get_bar()` is in scope,
|
2014-10-09 14:17:22 -05:00
|
|
|
// 3. do_it() panics.
|
2014-01-15 13:39:08 -06:00
|
|
|
//
|
|
|
|
// This led to a bug because `the top-most frame that was to be
|
2014-05-05 20:56:44 -05:00
|
|
|
// cleaned (which happens to be the partial cleanup of `box`) required
|
2014-01-15 13:39:08 -06: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 05:34:41 -06:00
|
|
|
// ignore-emscripten no threads support
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2015-01-07 19:25:56 -06:00
|
|
|
#![allow(unknown_features)]
|
|
|
|
#![feature(box_syntax)]
|
|
|
|
|
2015-02-17 17:24:34 -06:00
|
|
|
use std::thread;
|
2014-01-15 13:39:08 -06:00
|
|
|
|
|
|
|
enum Conzabble {
|
|
|
|
Bickwick(Foo)
|
|
|
|
}
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
struct Foo { field: Box<usize> }
|
2014-01-15 13:39:08 -06:00
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
fn do_it(x: &[usize]) -> Foo {
|
2014-10-09 14:17:22 -05:00
|
|
|
panic!()
|
2014-01-15 13:39:08 -06:00
|
|
|
}
|
|
|
|
|
2016-10-29 16:54:04 -05:00
|
|
|
fn get_bar(x: usize) -> Vec<usize> { vec![x * 2] }
|
2014-01-15 13:39:08 -06:00
|
|
|
|
|
|
|
pub fn fails() {
|
|
|
|
let x = 2;
|
2015-02-17 14:41:32 -06:00
|
|
|
let mut y: Vec<Box<_>> = Vec::new();
|
2015-02-01 20:53:25 -06:00
|
|
|
y.push(box Conzabble::Bickwick(do_it(&get_bar(x))));
|
2014-01-15 13:39:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2015-02-17 17:24:34 -06:00
|
|
|
thread::spawn(fails).join();
|
2014-01-15 13:39:08 -06:00
|
|
|
}
|