File tree 1 file changed +75
-0
lines changed
1 file changed +75
-0
lines changed Original file line number Diff line number Diff line change
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 : u64 = 1 ;
14
+
15
+ struct Foo ;
16
+
17
+ trait Bar {
18
+ fn foo1 ( & self ) ;
19
+ fn foo2 ( self ) ;
20
+ fn foo3 ( self : Box < Self > ) ;
21
+
22
+ fn bar1 ( & self ) {
23
+ unsafe { COUNT *= 7 ; }
24
+ }
25
+ fn bar2 ( self ) {
26
+ unsafe { COUNT *= 11 ; }
27
+ }
28
+ fn bar3 ( self : Box < Self > ) {
29
+ unsafe { COUNT *= 13 ; }
30
+ }
31
+ }
32
+
33
+ impl Bar for Foo {
34
+ fn foo1 ( & self ) {
35
+ unsafe { COUNT *= 2 ; }
36
+ }
37
+
38
+ fn foo2 ( self ) {
39
+ unsafe { COUNT *= 3 ; }
40
+ }
41
+
42
+ fn foo3 ( self : Box < Foo > ) {
43
+ unsafe { COUNT *= 5 ; }
44
+ }
45
+ }
46
+
47
+ impl Foo {
48
+ fn baz ( self ) {
49
+ unsafe { COUNT *= 17 ; }
50
+ // Test internal call.
51
+ Bar :: foo1 ( & self ) ;
52
+ Bar :: foo2 ( self ) ;
53
+ Bar :: foo3 ( box self ) ;
54
+
55
+ Bar :: bar1 ( & self ) ;
56
+ Bar :: bar2 ( self ) ;
57
+ Bar :: bar3 ( box self ) ;
58
+ }
59
+ }
60
+
61
+ fn main ( ) {
62
+ let x = Foo ;
63
+ // Test external call.
64
+ Bar :: foo1 ( & x) ;
65
+ Bar :: foo2 ( x) ;
66
+ Bar :: foo3 ( box x) ;
67
+
68
+ Bar :: bar1 ( & x) ;
69
+ Bar :: bar2 ( x) ;
70
+ Bar :: bar3 ( box x) ;
71
+
72
+ x. baz ( ) ;
73
+
74
+ unsafe { assert ! ( COUNT == 2u64 * 2 * 3 * 3 * 5 * 5 * 7 * 7 * 11 * 11 * 13 * 13 * 17 ) ; }
75
+ }
You can’t perform that action at this time.
0 commit comments