about summary refs log tree commit diff
path: root/library/coretests/tests/hint.rs
blob: 032bbc1dcc80f3a3b9b817c08c1b5b17d9ef49c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#[test]
fn select_unpredictable_drop() {
    use core::cell::Cell;
    struct X<'a>(&'a Cell<bool>);
    impl Drop for X<'_> {
        fn drop(&mut self) {
            self.0.set(true);
        }
    }

    let a_dropped = Cell::new(false);
    let b_dropped = Cell::new(false);
    let a = X(&a_dropped);
    let b = X(&b_dropped);
    assert!(!a_dropped.get());
    assert!(!b_dropped.get());
    let selected = core::hint::select_unpredictable(core::hint::black_box(true), a, b);
    assert!(!a_dropped.get());
    assert!(b_dropped.get());
    drop(selected);
    assert!(a_dropped.get());
    assert!(b_dropped.get());
}