]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-15763.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / issue-15763.rs
1 // Copyright 2014 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 #![allow(unknown_features)]
12 #![feature(box_syntax)]
13
14 #[derive(PartialEq, Show)]
15 struct Bar {
16     x: int
17 }
18 impl Drop for Bar {
19     fn drop(&mut self) {
20         assert_eq!(self.x, 22);
21     }
22 }
23
24 #[derive(PartialEq, Show)]
25 struct Foo {
26     x: Bar,
27     a: int
28 }
29
30 fn foo() -> Result<Foo, int> {
31     return Ok(Foo {
32         x: Bar { x: 22 },
33         a: return Err(32)
34     });
35 }
36
37 fn baz() -> Result<Foo, int> {
38     Ok(Foo {
39         x: Bar { x: 22 },
40         a: return Err(32)
41     })
42 }
43
44 // explicit immediate return
45 fn aa() -> int {
46     return 3;
47 }
48
49 // implicit immediate return
50 fn bb() -> int {
51     3
52 }
53
54 // implicit outptr return
55 fn cc() -> Result<int, int> {
56     Ok(3)
57 }
58
59 // explicit outptr return
60 fn dd() -> Result<int, int> {
61     return Ok(3);
62 }
63
64 trait A {
65     fn aaa(&self) -> int {
66         3
67     }
68     fn bbb(&self) -> int {
69         return 3;
70     }
71     fn ccc(&self) -> Result<int, int> {
72         Ok(3)
73     }
74     fn ddd(&self) -> Result<int, int> {
75         return Ok(3);
76     }
77 }
78
79 impl A for int {}
80
81 fn main() {
82     assert_eq!(foo(), Err(32));
83     assert_eq!(baz(), Err(32));
84
85     assert_eq!(aa(), 3);
86     assert_eq!(bb(), 3);
87     assert_eq!(cc().unwrap(), 3);
88     assert_eq!(dd().unwrap(), 3);
89
90     let i = box 32i as Box<A>;
91     assert_eq!(i.aaa(), 3);
92     let i = box 32i as Box<A>;
93     assert_eq!(i.bbb(), 3);
94     let i = box 32i as Box<A>;
95     assert_eq!(i.ccc().unwrap(), 3);
96     let i = box 32i as Box<A>;
97     assert_eq!(i.ddd().unwrap(), 3);
98 }