Skip to content

Commit d90a1de

Browse files
committed
Start sketching some traitorous code (xfail'd)
1 parent 43def06 commit d90a1de

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/test/run-pass/traits.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//xfail-test
2+
3+
// Sketching traits.
4+
5+
// methods with no implementation are required; methods with an
6+
// implementation are provided. No "req" keyword necessary.
7+
trait Eq {
8+
fn eq(a: self) -> bool;
9+
10+
fn neq(a: self) -> bool {
11+
!self.neq(a)
12+
}
13+
}
14+
15+
// The `<` is pronounced `extends`. Also under consideration is `<:`.
16+
// Just using `:` is frowned upon, because (paraphrasing dherman) `:`
17+
// is supposed to separate things from different universes.
18+
trait Ord < Eq {
19+
20+
fn lt(a: self) -> bool;
21+
22+
fn lte(a: self) -> bool {
23+
self.lt(a) || self.eq(a)
24+
}
25+
26+
fn gt(a: self) -> bool {
27+
!self.lt(a) && !self.eq(a)
28+
}
29+
30+
fn gte(a: self) -> bool {
31+
!self.lt(a)
32+
}
33+
}
34+
35+
// pronounced "impl of Ord for int" -- not sold on this yet
36+
impl int: Ord {
37+
fn lt(a: self) -> bool {
38+
self < a
39+
}
40+
41+
// is this the place to put this?
42+
fn eq(a: self) -> bool {
43+
self == a
44+
}
45+
}
46+

0 commit comments

Comments
 (0)