]> git.lizzy.rs Git - rust.git/blob - src/test/run-fail/unwind-box-res.rs
ce24d265504c75fbebe193da84082ebfa5f3e52e
[rust.git] / src / test / run-fail / unwind-box-res.rs
1 // Copyright 2012 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 // error-pattern:fail
12
13 #![feature(managed_boxes)]
14
15 extern crate debug;
16
17 use std::mem;
18 use std::gc::GC;
19
20 fn failfn() {
21     fail!();
22 }
23
24 struct r {
25   v: *int,
26 }
27
28 impl Drop for r {
29     fn drop(&mut self) {
30         unsafe {
31             let _v2: Box<int> = mem::transmute(self.v);
32         }
33     }
34 }
35
36 fn r(v: *int) -> r {
37     r {
38         v: v
39     }
40 }
41
42 fn main() {
43     unsafe {
44         let i1 = box 0;
45         let i1p = mem::transmute_copy(&i1);
46         mem::forget(i1);
47         let x = box(GC) r(i1p);
48         failfn();
49         println!("{:?}", x);
50     }
51 }