]> git.lizzy.rs Git - rust.git/blob - src/test/ui/drop/drop-struct-as-object.rs
Rollup merge of #97317 - GuillaumeGomez:gui-settings-text-click, r=jsha
[rust.git] / src / test / ui / drop / drop-struct-as-object.rs
1 // run-pass
2 #![allow(unused_variables)]
3 #![allow(non_upper_case_globals)]
4
5 // Test that destructor on a struct runs successfully after the struct
6 // is boxed and converted to an object.
7
8 static mut value: usize = 0;
9
10 struct Cat {
11     name : usize,
12 }
13
14 trait Dummy {
15     fn get(&self) -> usize;
16 }
17
18 impl Dummy for Cat {
19     fn get(&self) -> usize { self.name }
20 }
21
22 impl Drop for Cat {
23     fn drop(&mut self) {
24         unsafe { value = self.name; }
25     }
26 }
27
28 pub fn main() {
29     {
30         let x = Box::new(Cat {name: 22});
31         let nyan: Box<dyn Dummy> = x as Box<dyn Dummy>;
32     }
33     unsafe {
34         assert_eq!(value, 22);
35     }
36 }