]> git.lizzy.rs Git - rust.git/blob - src/test/ui/init-res-into-things.rs
Merge commit 'cd4810de42c57b64b74dae09c530a4c3a41f87b9' into libgccjit-codegen
[rust.git] / src / test / ui / init-res-into-things.rs
1 // run-pass
2
3 #![allow(non_camel_case_types)]
4 #![allow(dead_code)]
5 #![feature(box_syntax)]
6
7 use std::cell::Cell;
8
9 // Resources can't be copied, but storing into data structures counts
10 // as a move unless the stored thing is used afterwards.
11
12 struct r<'a> {
13     i: &'a Cell<isize>,
14 }
15
16 struct BoxR<'a> { x: r<'a> }
17
18 impl<'a> Drop for r<'a> {
19     fn drop(&mut self) {
20         self.i.set(self.i.get() + 1)
21     }
22 }
23
24 fn r(i: &Cell<isize>) -> r {
25     r {
26         i: i
27     }
28 }
29
30 fn test_rec() {
31     let i = &Cell::new(0);
32     {
33         let _a = BoxR {x: r(i)};
34     }
35     assert_eq!(i.get(), 1);
36 }
37
38 fn test_tag() {
39     enum t<'a> {
40         t0(r<'a>),
41     }
42
43     let i = &Cell::new(0);
44     {
45         let _a = t::t0(r(i));
46     }
47     assert_eq!(i.get(), 1);
48 }
49
50 fn test_tup() {
51     let i = &Cell::new(0);
52     {
53         let _a = (r(i), 0);
54     }
55     assert_eq!(i.get(), 1);
56 }
57
58 fn test_unique() {
59     let i = &Cell::new(0);
60     {
61         let _a: Box<_> = box r(i);
62     }
63     assert_eq!(i.get(), 1);
64 }
65
66 fn test_unique_rec() {
67     let i = &Cell::new(0);
68     {
69         let _a: Box<_> = box BoxR {
70             x: r(i)
71         };
72     }
73     assert_eq!(i.get(), 1);
74 }
75
76 pub fn main() {
77     test_rec();
78     test_tag();
79     test_tup();
80     test_unique();
81     test_unique_rec();
82 }