summaryrefslogtreecommitdiffstats
path: root/tests/ui/structs-enums/resource-in-struct.rs
blob: 9613ca62a49e62c75f286c8ded5871b3752293c1 (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
34
35
36
37
// run-pass
#![allow(non_camel_case_types)]

// Ensures that class dtors run if the object is inside an enum
// variant

use std::cell::Cell;

type closable<'a> = &'a Cell<bool>;

struct close_res<'a> {
  i: closable<'a>,

}

impl<'a> Drop for close_res<'a> {
    fn drop(&mut self) {
        self.i.set(false);
    }
}

fn close_res(i: closable) -> close_res {
    close_res {
        i: i
    }
}

enum option<T> { none, some(#[allow(unused_tuple_struct_fields)] T), }

fn sink(_res: option<close_res>) { }

pub fn main() {
    let c = &Cell::new(true);
    sink(option::none);
    sink(option::some(close_res(c)));
    assert!(!c.get());
}