]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-valgrind/cleanup-auto-borrow-obj.rs
Auto merge of #64230 - Centril:rollup-vxyczjq, r=Centril
[rust.git] / src / test / run-pass-valgrind / cleanup-auto-borrow-obj.rs
1 // This would previously leak the Box<Trait> because we wouldn't
2 // schedule cleanups when auto borrowing trait objects.
3 // This program should be valgrind clean.
4
5 #![feature(box_syntax)]
6
7 static mut DROP_RAN: bool = false;
8
9 struct Foo;
10 impl Drop for Foo {
11     fn drop(&mut self) {
12         unsafe { DROP_RAN = true; }
13     }
14 }
15
16
17 trait Trait { fn dummy(&self) { } }
18 impl Trait for Foo {}
19
20 pub fn main() {
21     {
22         let _x: &Trait = &*(box Foo as Box<Trait>);
23     }
24     unsafe {
25         assert!(DROP_RAN);
26     }
27 }