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