File tree Expand file tree Collapse file tree 6 files changed +75
-1
lines changed
branches/try/src/test/run-pass
module-polymorphism4-files Expand file tree Collapse file tree 6 files changed +75
-1
lines changed Original file line number Diff line number Diff line change 2
2
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5
- refs/heads/try: 611061b6c31ec7f96025b07cee53cfb7fe8ee3d9
5
+ refs/heads/try: 658b6a741b7d2bd01c7e14211b4299f12c0a3ebf
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
Original file line number Diff line number Diff line change
1
+ type T = cat ;
2
+
3
+ enum cat {
4
+ howlycat,
5
+ meowlycat
6
+ }
7
+
8
+ fn animal ( ) -> str { "cat" }
9
+ fn talk ( c : cat ) -> str {
10
+ alt c {
11
+ howlycat { "howl" }
12
+ meowlycat { "meow" }
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ type T = dog ;
2
+
3
+ enum dog {
4
+ dog
5
+ }
6
+
7
+ fn animal ( ) -> str { "dog" }
8
+ fn talk ( _d : dog ) -> str { "woof" }
9
+
Original file line number Diff line number Diff line change
1
+ impl talky for T {
2
+
3
+ // 'animal' and 'talk' functions are implemented by the module
4
+ // instantiating the talky trait. They are 'abstract'
5
+ fn says ( ) -> str {
6
+ animal ( ) + " says '" + talk ( self ) + "'"
7
+ }
8
+
9
+ }
Original file line number Diff line number Diff line change
1
+ #[no_core];
2
+
3
+
4
+ #[path = "module-polymorphism4-files"]
5
+ mod cat {
6
+
7
+ import inst::*;
8
+
9
+ #[path = "cat.rs"]
10
+ mod inst;
11
+
12
+ #[path = "trait.rs"]
13
+ mod trait;
14
+
15
+ }
16
+
17
+ #[path = "module-polymorphism4-files"]
18
+ mod dog {
19
+
20
+ import inst::*;
21
+
22
+ #[path = "dog.rs"]
23
+ mod inst;
24
+
25
+ #[path = "trait.rs"]
26
+ mod trait;
27
+
28
+ }
Original file line number Diff line number Diff line change
1
+ // This isn't really xfailed; it's used by the
2
+ // module-polymorphism.rc test
3
+ // xfail-test
4
+
5
+ fn main ( ) {
6
+ import cat:: trait:: talky;
7
+ import dog:: trait:: talky;
8
+ let cat1 = cat:: inst:: meowlycat;
9
+ let cat2 = cat:: inst:: howlycat;
10
+ let dog = dog:: inst:: dog;
11
+ assert cat1. says ( ) == "cat says 'meow'" ;
12
+ assert cat2. says ( ) == "cat says 'howl'" ;
13
+ assert dog. says ( ) == "dog says 'woof'" ;
14
+ }
You can’t perform that action at this time.
0 commit comments