]> git.lizzy.rs Git - rust.git/blob - src/test/auxiliary/method_self_arg2.rs
Rollup merge of #28991 - goyox86:goyox86/rustfmting-liblog-II, r=alexcrichton
[rust.git] / src / test / auxiliary / method_self_arg2.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 #![crate_type = "lib"]
12
13 #![allow(unknown_features)]
14 #![feature(box_syntax)]
15
16 static mut COUNT: u64 = 1;
17
18 pub fn get_count() -> u64 { unsafe { COUNT } }
19
20 #[derive(Copy, Clone)]
21 pub struct Foo;
22
23 impl Foo {
24     pub fn run_trait(self) {
25         unsafe { COUNT *= 17; }
26         // Test internal call.
27         Bar::foo1(&self);
28         Bar::foo2(self);
29         Bar::foo3(box self);
30
31         Bar::bar1(&self);
32         Bar::bar2(self);
33         Bar::bar3(box self);
34     }
35 }
36
37 pub trait Bar : Sized {
38     fn foo1(&self);
39     fn foo2(self);
40     fn foo3(self: Box<Self>);
41
42     fn bar1(&self) {
43         unsafe { COUNT *= 7; }
44     }
45     fn bar2(self) {
46         unsafe { COUNT *= 11; }
47     }
48     fn bar3(self: Box<Self>) {
49         unsafe { COUNT *= 13; }
50     }
51 }
52
53 impl Bar for Foo {
54     fn foo1(&self) {
55         unsafe { COUNT *= 2; }
56     }
57
58     fn foo2(self) {
59         unsafe { COUNT *= 3; }
60     }
61
62     fn foo3(self: Box<Foo>) {
63         unsafe { COUNT *= 5; }
64     }
65 }