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