]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass-valgrind/cleanup-auto-borrow-obj.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / run-pass-valgrind / cleanup-auto-borrow-obj.rs
CommitLineData
1a4d82fc
JJ
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
1a4d82fc
JJ
5static mut DROP_RAN: bool = false;
6
7struct Foo;
8impl Drop for Foo {
9 fn drop(&mut self) {
10 unsafe { DROP_RAN = true; }
11 }
12}
13
14
85aaf69f 15trait Trait { fn dummy(&self) { } }
1a4d82fc
JJ
16impl Trait for Foo {}
17
18pub fn main() {
19 {
f2b60f7d 20 let _x: &Trait = &*(Box::new(Foo) as Box<Trait>);
1a4d82fc
JJ
21 }
22 unsafe {
23 assert!(DROP_RAN);
24 }
25}