]> git.lizzy.rs Git - rust.git/blob - src/test/ui/methods/method-self-arg-trait.rs
Merge commit '3c7e7dbc1583a0b06df5bd7623dd354a4debd23d' into clippyup
[rust.git] / src / test / ui / methods / method-self-arg-trait.rs
1 // run-pass
2 // Test method calls with self as an argument
3
4 static mut COUNT: u64 = 1;
5
6 #[derive(Copy, Clone)]
7 struct Foo;
8
9 trait Bar : Sized {
10     fn foo1(&self);
11     fn foo2(self);
12     fn foo3(self: Box<Self>);
13
14     fn bar1(&self) {
15         unsafe { COUNT *= 7; }
16     }
17     fn bar2(self) {
18         unsafe { COUNT *= 11; }
19     }
20     fn bar3(self: Box<Self>) {
21         unsafe { COUNT *= 13; }
22     }
23 }
24
25 impl Bar for Foo {
26     fn foo1(&self) {
27         unsafe { COUNT *= 2; }
28     }
29
30     fn foo2(self) {
31         unsafe { COUNT *= 3; }
32     }
33
34     fn foo3(self: Box<Foo>) {
35         unsafe { COUNT *= 5; }
36     }
37 }
38
39 impl Foo {
40     fn baz(self) {
41         unsafe { COUNT *= 17; }
42         // Test internal call.
43         Bar::foo1(&self);
44         Bar::foo2(self);
45         Bar::foo3(Box::new(self));
46
47         Bar::bar1(&self);
48         Bar::bar2(self);
49         Bar::bar3(Box::new(self));
50     }
51 }
52
53 fn main() {
54     let x = Foo;
55     // Test external call.
56     Bar::foo1(&x);
57     Bar::foo2(x);
58     Bar::foo3(Box::new(x));
59
60     Bar::bar1(&x);
61     Bar::bar2(x);
62     Bar::bar3(Box::new(x));
63
64     x.baz();
65
66     unsafe { assert_eq!(COUNT, 2*2*3*3*5*5*7*7*11*11*13*13*17); }
67 }