]> git.lizzy.rs Git - rust.git/blob - src/test/ui/methods/method-self-arg.rs
Merge commit '3e7c6dec244539970b593824334876f8b6ed0b18' into clippyup
[rust.git] / src / test / ui / methods / method-self-arg.rs
1 // run-pass
2 // Test method calls with self as an argument
3
4 #![feature(box_syntax)]
5
6 static mut COUNT: usize = 1;
7
8 #[derive(Copy, Clone)]
9 struct Foo;
10
11 impl Foo {
12     fn foo(self, x: &Foo) {
13         unsafe { COUNT *= 2; }
14         // Test internal call.
15         Foo::bar(&self);
16         Foo::bar(x);
17
18         Foo::baz(self);
19         Foo::baz(*x);
20
21         Foo::qux(box self);
22         Foo::qux(box *x);
23     }
24
25     fn bar(&self) {
26         unsafe { COUNT *= 3; }
27     }
28
29     fn baz(self) {
30         unsafe { COUNT *= 5; }
31     }
32
33     fn qux(self: Box<Foo>) {
34         unsafe { COUNT *= 7; }
35     }
36 }
37
38 fn main() {
39     let x = Foo;
40     // Test external call.
41     Foo::bar(&x);
42     Foo::baz(x);
43     Foo::qux(box x);
44
45     x.foo(&x);
46
47     unsafe { assert_eq!(COUNT, 2*3*3*3*5*5*5*7*7*7); }
48 }