]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/method-self-arg.rs
auto merge of #19514 : jbranchaud/rust/add-btree-set-bitor, r=Gankro
[rust.git] / src / test / run-pass / method-self-arg.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 // Test method calls with self as an argument
12
13 static mut COUNT: uint = 1;
14
15 struct Foo;
16
17 impl Copy for Foo {}
18
19 impl Foo {
20     fn foo(self, x: &Foo) {
21         unsafe { COUNT *= 2; }
22         // Test internal call.
23         Foo::bar(&self);
24         Foo::bar(x);
25
26         Foo::baz(self);
27         Foo::baz(*x);
28
29         Foo::qux(box self);
30         Foo::qux(box *x);
31     }
32
33     fn bar(&self) {
34         unsafe { COUNT *= 3; }
35     }
36
37     fn baz(self) {
38         unsafe { COUNT *= 5; }
39     }
40
41     fn qux(self: Box<Foo>) {
42         unsafe { COUNT *= 7; }
43     }
44 }
45
46 fn main() {
47     let x = Foo;
48     // Test external call.
49     Foo::bar(&x);
50     Foo::baz(x);
51     Foo::qux(box x);
52
53     x.foo(&x);
54
55     unsafe { assert!(COUNT == 2u*3*3*3*5*5*5*7*7*7); }
56 }