]> git.proxmox.com Git - rustc.git/blame - src/test/ui/drop/drop-struct-as-object.rs
Update unsuspicious file list
[rustc.git] / src / test / ui / drop / drop-struct-as-object.rs
CommitLineData
b7449926 1// run-pass
0bf4aa26 2#![allow(unused_variables)]
b7449926
XL
3#![allow(non_upper_case_globals)]
4
1a4d82fc
JJ
5// Test that destructor on a struct runs successfully after the struct
6// is boxed and converted to an object.
7
c34b1796 8static mut value: usize = 0;
1a4d82fc
JJ
9
10struct Cat {
c34b1796 11 name : usize,
1a4d82fc
JJ
12}
13
14trait Dummy {
c34b1796 15 fn get(&self) -> usize;
1a4d82fc
JJ
16}
17
18impl Dummy for Cat {
c34b1796 19 fn get(&self) -> usize { self.name }
1a4d82fc
JJ
20}
21
22impl Drop for Cat {
23 fn drop(&mut self) {
24 unsafe { value = self.name; }
25 }
26}
27
28pub fn main() {
29 {
c295e0f8 30 let x = Box::new(Cat {name: 22});
dc9dc135 31 let nyan: Box<dyn Dummy> = x as Box<dyn Dummy>;
1a4d82fc
JJ
32 }
33 unsafe {
34 assert_eq!(value, 22);
35 }
36}