about summary refs log tree commit diff
path: root/tests/ui/drop/for-expr-temporary-drop-scope.rs
blob: c6f80842ee63611257400fe4400853ac331a42ce (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
25
26
27
28
29
30
31
32
33
//! Check that temporaries in the for into-iterable expr are not dropped
//! until the end of the for expr.

//@ run-pass

static mut FLAGS: u64 = 0;

struct AddFlags {
    bits: u64,
}

impl Drop for AddFlags {
    fn drop(&mut self) {
        unsafe {
            FLAGS += self.bits;
        }
    }
}

fn check_flags(expected: u64) {
    unsafe {
        let actual = FLAGS;
        FLAGS = 0;
        assert_eq!(actual, expected, "flags {}, expected {}", actual, expected);
    }
}

fn main() {
    for _ in &[AddFlags { bits: 1 }] {
        check_flags(0);
    }
    check_flags(1);
}