]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-valgrind/cleanup-auto-borrow-obj.rs
Merge commit '1411a98352ba6bee8ba3b0131c9243e5db1e6a2e' into sync_cg_clif-2021-12-31
[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 }