]> git.lizzy.rs Git - rust.git/blob - tests/run-pass-valgrind/cleanup-auto-borrow-obj.rs
Rollup merge of #107777 - compiler-errors:derive_const-actually-derive-const, r=fee1...
[rust.git] / tests / 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 static mut DROP_RAN: bool = false;
6
7 struct Foo;
8 impl Drop for Foo {
9     fn drop(&mut self) {
10         unsafe { DROP_RAN = true; }
11     }
12 }
13
14
15 trait Trait { fn dummy(&self) { } }
16 impl Trait for Foo {}
17
18 pub fn main() {
19     {
20         let _x: &Trait = &*(Box::new(Foo) as Box<Trait>);
21     }
22     unsafe {
23         assert!(DROP_RAN);
24     }
25 }