about summary refs log tree commit diff
path: root/src/tools/miri/tests/pass/drop_through_trait_object_rc.rs
blob: 7806c0252d270452b1a7d96dfe51933c1ab14086 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
trait Foo {}

struct Bar;

static mut DROP_CALLED: bool = false;

impl Drop for Bar {
    fn drop(&mut self) {
        unsafe {
            DROP_CALLED = true;
        }
    }
}

impl Foo for Bar {}

use std::rc::Rc;

fn main() {
    let b: Rc<dyn Foo> = Rc::new(Bar);
    assert!(unsafe { !DROP_CALLED });
    drop(b);
    assert!(unsafe { DROP_CALLED });
}