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