2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2018-09-25 16:51:35 -05:00
|
|
|
#![allow(unused_variables)]
|
2018-08-31 08:02:01 -05:00
|
|
|
#![allow(non_upper_case_globals)]
|
|
|
|
|
2014-09-12 09:45:39 -05:00
|
|
|
// Test that destructor on a struct runs successfully after the struct
|
|
|
|
// is boxed and converted to an object.
|
|
|
|
|
2015-01-07 19:25:56 -06:00
|
|
|
#![feature(box_syntax)]
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
static mut value: usize = 0;
|
2014-09-12 09:45:39 -05:00
|
|
|
|
|
|
|
struct Cat {
|
2015-03-25 19:06:52 -05:00
|
|
|
name : usize,
|
2014-09-12 09:45:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
trait Dummy {
|
2015-03-25 19:06:52 -05:00
|
|
|
fn get(&self) -> usize;
|
2014-09-12 09:45:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Dummy for Cat {
|
2015-03-25 19:06:52 -05:00
|
|
|
fn get(&self) -> usize { self.name }
|
2014-09-12 09:45:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for Cat {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe { value = self.name; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
{
|
|
|
|
let x = box Cat {name: 22};
|
2019-05-28 13:47:21 -05:00
|
|
|
let nyan: Box<dyn Dummy> = x as Box<dyn Dummy>;
|
2014-09-12 09:45:39 -05:00
|
|
|
}
|
|
|
|
unsafe {
|
|
|
|
assert_eq!(value, 22);
|
|
|
|
}
|
|
|
|
}
|