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