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