]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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 | // Test method calls with self as an argument | |
12 | ||
c34b1796 AL |
13 | // pretty-expanded FIXME #23616 |
14 | ||
1a4d82fc JJ |
15 | #![allow(unknown_features)] |
16 | #![feature(box_syntax)] | |
17 | ||
c34b1796 | 18 | static mut COUNT: usize = 1; |
1a4d82fc | 19 | |
c34b1796 | 20 | #[derive(Copy, Clone)] |
1a4d82fc JJ |
21 | struct Foo; |
22 | ||
1a4d82fc JJ |
23 | impl Foo { |
24 | fn foo(self, x: &Foo) { | |
25 | unsafe { COUNT *= 2; } | |
26 | // Test internal call. | |
27 | Foo::bar(&self); | |
28 | Foo::bar(x); | |
29 | ||
30 | Foo::baz(self); | |
31 | Foo::baz(*x); | |
32 | ||
33 | Foo::qux(box self); | |
34 | Foo::qux(box *x); | |
35 | } | |
36 | ||
37 | fn bar(&self) { | |
38 | unsafe { COUNT *= 3; } | |
39 | } | |
40 | ||
41 | fn baz(self) { | |
42 | unsafe { COUNT *= 5; } | |
43 | } | |
44 | ||
45 | fn qux(self: Box<Foo>) { | |
46 | unsafe { COUNT *= 7; } | |
47 | } | |
48 | } | |
49 | ||
50 | fn main() { | |
51 | let x = Foo; | |
52 | // Test external call. | |
53 | Foo::bar(&x); | |
54 | Foo::baz(x); | |
55 | Foo::qux(box x); | |
56 | ||
57 | x.foo(&x); | |
58 | ||
c34b1796 | 59 | unsafe { assert!(COUNT == 2*3*3*3*5*5*5*7*7*7); } |
1a4d82fc | 60 | } |