]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/init-res-into-things.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / run-pass / init-res-into-things.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // pretty-expanded FIXME #23616
12
13 #![allow(unknown_features)]
14 #![feature(box_syntax)]
15 #![feature(unsafe_destructor)]
16
17 use std::cell::Cell;
18
19 // Resources can't be copied, but storing into data structures counts
20 // as a move unless the stored thing is used afterwards.
21
22 struct r<'a> {
23 i: &'a Cell<isize>,
24 }
25
26 struct BoxR<'a> { x: r<'a> }
27
28 #[unsafe_destructor]
29 impl<'a> Drop for r<'a> {
30 fn drop(&mut self) {
31 self.i.set(self.i.get() + 1)
32 }
33 }
34
35 fn r(i: &Cell<isize>) -> r {
36 r {
37 i: i
38 }
39 }
40
41 fn test_rec() {
42 let i = &Cell::new(0);
43 {
44 let _a = BoxR {x: r(i)};
45 }
46 assert_eq!(i.get(), 1);
47 }
48
49 fn test_tag() {
50 enum t<'a> {
51 t0(r<'a>),
52 }
53
54 let i = &Cell::new(0);
55 {
56 let _a = t::t0(r(i));
57 }
58 assert_eq!(i.get(), 1);
59 }
60
61 fn test_tup() {
62 let i = &Cell::new(0);
63 {
64 let _a = (r(i), 0);
65 }
66 assert_eq!(i.get(), 1);
67 }
68
69 fn test_unique() {
70 let i = &Cell::new(0);
71 {
72 let _a: Box<_> = box r(i);
73 }
74 assert_eq!(i.get(), 1);
75 }
76
77 fn test_unique_rec() {
78 let i = &Cell::new(0);
79 {
80 let _a: Box<_> = box BoxR {
81 x: r(i)
82 };
83 }
84 assert_eq!(i.get(), 1);
85 }
86
87 pub fn main() {
88 test_rec();
89 test_tag();
90 test_tup();
91 test_unique();
92 test_unique_rec();
93 }