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