Skip to content

Commit 7ff7e62

Browse files
committed
---
yaml --- r: 30186 b: refs/heads/incoming c: a1c11ca h: refs/heads/master v: v3
1 parent 15975d7 commit 7ff7e62

File tree

15 files changed

+193
-24
lines changed

15 files changed

+193
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 70d3633c0b66c247b97f721653d33264ddfc680f
9+
refs/heads/incoming: a1c11cab2dc56483cf9fe6d25af43b2f602d5155
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/cargo/cargo.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ impl package : cmp::Ord {
4242
if self.versions.lt(other.versions) { return true; }
4343
return false;
4444
}
45+
pure fn le(&&other: package) -> bool {
46+
if self.name.lt(other.name) { return true; }
47+
if other.name.lt(self.name) { return false; }
48+
if self.uuid.lt(other.uuid) { return true; }
49+
if other.uuid.lt(self.uuid) { return false; }
50+
if self.url.lt(other.url) { return true; }
51+
if other.url.lt(self.url) { return false; }
52+
if self.method.lt(other.method) { return true; }
53+
if other.method.lt(self.method) { return false; }
54+
if self.description.lt(other.description) { return true; }
55+
if other.description.lt(self.description) { return false; }
56+
if self.tags.lt(other.tags) { return true; }
57+
if other.tags.lt(self.tags) { return false; }
58+
if self.versions.le(other.versions) { return true; }
59+
return false;
60+
}
61+
pure fn ge(&&other: package) -> bool { !other.lt(self) }
62+
pure fn gt(&&other: package) -> bool { !other.le(self) }
4563
}
4664

4765
type local_package = {

branches/incoming/src/libcore/box.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ impl<T:Eq> @const T : Eq {
1919

2020
impl<T:Ord> @const T : Ord {
2121
pure fn lt(&&other: @const T) -> bool { *self < *other }
22+
pure fn le(&&other: @const T) -> bool { *self <= *other }
23+
pure fn ge(&&other: @const T) -> bool { *self >= *other }
24+
pure fn gt(&&other: @const T) -> bool { *self > *other }
2225
}
2326

2427
#[test]

branches/incoming/src/libcore/cmp.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@
99
#[lang="ord"]
1010
trait Ord {
1111
pure fn lt(&&other: self) -> bool;
12+
pure fn le(&&other: self) -> bool;
13+
pure fn ge(&&other: self) -> bool;
14+
pure fn gt(&&other: self) -> bool;
1215
}
1316

1417
#[cfg(test)]
1518
trait Ord {
1619
pure fn lt(&&other: self) -> bool;
20+
pure fn le(&&other: self) -> bool;
21+
pure fn ge(&&other: self) -> bool;
22+
pure fn gt(&&other: self) -> bool;
1723
}
1824

1925
#[cfg(notest)]
@@ -38,3 +44,12 @@ pure fn le<T: Ord Eq>(v1: &T, v2: &T) -> bool {
3844
pure fn eq<T: Eq>(v1: &T, v2: &T) -> bool {
3945
v1.eq(v2)
4046
}
47+
48+
pure fn ge<T: Ord>(v1: &T, v2: &T) -> bool {
49+
v1.ge(v2)
50+
}
51+
52+
pure fn gt<T: Ord>(v1: &T, v2: &T) -> bool {
53+
v1.gt(v2)
54+
}
55+

branches/incoming/src/libcore/float.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ impl float: Eq {
421421

422422
impl float: Ord {
423423
pure fn lt(&&other: float) -> bool { self < other }
424+
pure fn le(&&other: float) -> bool { self <= other }
425+
pure fn ge(&&other: float) -> bool { self >= other }
426+
pure fn gt(&&other: float) -> bool { self > other }
424427
}
425428

426429
impl float: num::Num {

branches/incoming/src/libcore/int-template.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ pure fn abs(i: T) -> T {
6868
}
6969

7070
impl T: Ord {
71-
pure fn lt(&&other: T) -> bool {
72-
return self < other;
73-
}
71+
pure fn lt(&&other: T) -> bool { return self < other; }
72+
pure fn le(&&other: T) -> bool { return self <= other; }
73+
pure fn ge(&&other: T) -> bool { return self >= other; }
74+
pure fn gt(&&other: T) -> bool { return self > other; }
7475
}
7576

7677
impl T: Eq {

branches/incoming/src/libcore/ptr.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ impl<T> *const T : Ord {
188188
let b: uint = unsafe::reinterpret_cast(other);
189189
return a < b;
190190
}
191+
pure fn le(&&other: *const T) -> bool unsafe {
192+
let a: uint = unsafe::reinterpret_cast(self);
193+
let b: uint = unsafe::reinterpret_cast(other);
194+
return a <= b;
195+
}
196+
pure fn ge(&&other: *const T) -> bool unsafe {
197+
let a: uint = unsafe::reinterpret_cast(self);
198+
let b: uint = unsafe::reinterpret_cast(other);
199+
return a >= b;
200+
}
201+
pure fn gt(&&other: *const T) -> bool unsafe {
202+
let a: uint = unsafe::reinterpret_cast(self);
203+
let b: uint = unsafe::reinterpret_cast(other);
204+
return a > b;
205+
}
191206
}
192207

193208
// Equality for region pointers
@@ -199,9 +214,10 @@ impl<T:Eq> &const T : Eq {
199214

200215
// Comparison for region pointers
201216
impl<T:Ord> &const T : Ord {
202-
pure fn lt(&&other: &const T) -> bool {
203-
return *self < *other;
204-
}
217+
pure fn lt(&&other: &const T) -> bool { *self < *other }
218+
pure fn le(&&other: &const T) -> bool { *self <= *other }
219+
pure fn ge(&&other: &const T) -> bool { *self >= *other }
220+
pure fn gt(&&other: &const T) -> bool { *self > *other }
205221
}
206222

207223
#[test]

branches/incoming/src/libcore/str.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,30 @@ pure fn lt(a: &str, b: &str) -> bool {
707707
}
708708

709709
/// Bytewise less than or equal
710-
pure fn le(a: &~str, b: &~str) -> bool { *a <= *b }
710+
pure fn le(a: &str, b: &str) -> bool {
711+
let (a_len, b_len) = (a.len(), b.len());
712+
let mut end = uint::min(&a_len, &b_len);
713+
714+
let mut i = 0;
715+
while i < end {
716+
let (c_a, c_b) = (a[i], b[i]);
717+
if c_a < c_b { return true; }
718+
if c_a > c_b { return false; }
719+
i += 1;
720+
}
721+
722+
return a_len <= b_len;
723+
}
724+
725+
/// Bytewise greater than or equal
726+
pure fn ge(a: &str, b: &str) -> bool {
727+
!lt(b, a)
728+
}
729+
730+
/// Bytewise greater than
731+
pure fn gt(a: &str, b: &str) -> bool {
732+
!le(b, a)
733+
}
711734

712735
impl &str: Eq {
713736
#[inline(always)]
@@ -733,16 +756,34 @@ impl @str: Eq {
733756
impl ~str : Ord {
734757
#[inline(always)]
735758
pure fn lt(&&other: ~str) -> bool { lt(self, other) }
759+
#[inline(always)]
760+
pure fn le(&&other: ~str) -> bool { le(self, other) }
761+
#[inline(always)]
762+
pure fn ge(&&other: ~str) -> bool { ge(self, other) }
763+
#[inline(always)]
764+
pure fn gt(&&other: ~str) -> bool { gt(self, other) }
736765
}
737766

738767
impl &str : Ord {
739768
#[inline(always)]
740769
pure fn lt(&&other: &str) -> bool { lt(self, other) }
770+
#[inline(always)]
771+
pure fn le(&&other: &str) -> bool { le(self, other) }
772+
#[inline(always)]
773+
pure fn ge(&&other: &str) -> bool { ge(self, other) }
774+
#[inline(always)]
775+
pure fn gt(&&other: &str) -> bool { gt(self, other) }
741776
}
742777

743778
impl @str : Ord {
744779
#[inline(always)]
745780
pure fn lt(&&other: @str) -> bool { lt(self, other) }
781+
#[inline(always)]
782+
pure fn le(&&other: @str) -> bool { le(self, other) }
783+
#[inline(always)]
784+
pure fn ge(&&other: @str) -> bool { ge(self, other) }
785+
#[inline(always)]
786+
pure fn gt(&&other: @str) -> bool { gt(self, other) }
746787
}
747788

748789
/// String hash function

branches/incoming/src/libcore/tuple.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ impl<A: Ord, B: Ord> (A, B): Ord {
9696
}
9797
}
9898
}
99+
pure fn le(&&other: (A, B)) -> bool {
100+
match self {
101+
(self_a, self_b) => {
102+
match other {
103+
(other_a, other_b) => {
104+
if self_a.lt(other_a) { return true; }
105+
if other_a.lt(self_a) { return false; }
106+
if self_b.le(other_b) { return true; }
107+
return false;
108+
}
109+
}
110+
}
111+
}
112+
}
113+
pure fn ge(&&other: (A, B)) -> bool { !other.lt(self) }
114+
pure fn gt(&&other: (A, B)) -> bool { !other.ge(self) }
99115
}
100116

101117
impl<A: Eq, B: Eq, C: Eq> (A, B, C): Eq {
@@ -133,6 +149,24 @@ impl<A: Ord, B: Ord, C: Ord> (A, B, C): Ord {
133149
}
134150
}
135151
}
152+
pure fn le(&&other: (A, B, C)) -> bool {
153+
match self {
154+
(self_a, self_b, self_c) => {
155+
match other {
156+
(other_a, other_b, other_c) => {
157+
if self_a.lt(other_a) { return true; }
158+
if other_a.lt(self_a) { return false; }
159+
if self_b.lt(other_b) { return true; }
160+
if other_b.lt(self_b) { return false; }
161+
if self_c.le(other_c) { return true; }
162+
return false;
163+
}
164+
}
165+
}
166+
}
167+
}
168+
pure fn ge(&&other: (A, B, C)) -> bool { !other.lt(self) }
169+
pure fn gt(&&other: (A, B, C)) -> bool { !other.ge(self) }
136170
}
137171

138172
#[test]

branches/incoming/src/libcore/uint-template.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ pure fn compl(i: T) -> T {
6161
}
6262

6363
impl T: Ord {
64-
pure fn lt(&&other: T) -> bool {
65-
return self < other;
66-
}
64+
pure fn lt(&&other: T) -> bool { self < other }
65+
pure fn le(&&other: T) -> bool { self <= other }
66+
pure fn ge(&&other: T) -> bool { self >= other }
67+
pure fn gt(&&other: T) -> bool { self > other }
6768
}
6869

6970
impl T: Eq {

branches/incoming/src/libcore/uniq.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ impl<T:Eq> ~const T : Eq {
88

99
impl<T:Ord> ~const T : Ord {
1010
pure fn lt(&&other: ~const T) -> bool { *self < *other }
11+
pure fn le(&&other: ~const T) -> bool { *self <= *other }
12+
pure fn ge(&&other: ~const T) -> bool { *self >= *other }
13+
pure fn gt(&&other: ~const T) -> bool { *self > *other }
1114
}
1215

branches/incoming/src/libcore/vec.rs

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,25 +1443,55 @@ pure fn lt<T: Ord>(a: &[T], b: &[T]) -> bool {
14431443
return a_len < b_len;
14441444
}
14451445

1446+
pure fn le<T: Ord>(a: &[T], b: &[T]) -> bool {
1447+
let (a_len, b_len) = (a.len(), b.len());
1448+
let mut end = uint::min(&a_len, &b_len);
1449+
1450+
let mut i = 0;
1451+
while i < end {
1452+
let (c_a, c_b) = (&a[i], &b[i]);
1453+
if *c_a < *c_b { return true; }
1454+
if *c_a > *c_b { return false; }
1455+
i += 1;
1456+
}
1457+
1458+
return a_len <= b_len;
1459+
}
1460+
1461+
pure fn ge<T: Ord>(a: &[T], b: &[T]) -> bool { !lt(b, a) }
1462+
pure fn gt<T: Ord>(a: &[T], b: &[T]) -> bool { !le(b, a) }
1463+
14461464
impl<T: Ord> &[T]: Ord {
14471465
#[inline(always)]
1448-
pure fn lt(&&other: &[T]) -> bool {
1449-
lt(self, other)
1450-
}
1466+
pure fn lt(&&other: &[T]) -> bool { lt(self, other) }
1467+
#[inline(always)]
1468+
pure fn le(&&other: &[T]) -> bool { le(self, other) }
1469+
#[inline(always)]
1470+
pure fn ge(&&other: &[T]) -> bool { ge(self, other) }
1471+
#[inline(always)]
1472+
pure fn gt(&&other: &[T]) -> bool { gt(self, other) }
14511473
}
14521474

14531475
impl<T: Ord> ~[T]: Ord {
14541476
#[inline(always)]
1455-
pure fn lt(&&other: ~[T]) -> bool {
1456-
lt(self, other)
1457-
}
1477+
pure fn lt(&&other: ~[T]) -> bool { lt(self, other) }
1478+
#[inline(always)]
1479+
pure fn le(&&other: ~[T]) -> bool { le(self, other) }
1480+
#[inline(always)]
1481+
pure fn ge(&&other: ~[T]) -> bool { ge(self, other) }
1482+
#[inline(always)]
1483+
pure fn gt(&&other: ~[T]) -> bool { gt(self, other) }
14581484
}
14591485

14601486
impl<T: Ord> @[T]: Ord {
14611487
#[inline(always)]
1462-
pure fn lt(&&other: @[T]) -> bool {
1463-
lt(self, other)
1464-
}
1488+
pure fn lt(&&other: @[T]) -> bool { lt(self, other) }
1489+
#[inline(always)]
1490+
pure fn le(&&other: @[T]) -> bool { le(self, other) }
1491+
#[inline(always)]
1492+
pure fn ge(&&other: @[T]) -> bool { ge(self, other) }
1493+
#[inline(always)]
1494+
pure fn gt(&&other: @[T]) -> bool { gt(self, other) }
14651495
}
14661496

14671497
#[cfg(notest)]

branches/incoming/src/libstd/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn print_failures(st: console_test_state) {
217217
st.out.write_line(~"\nfailures:");
218218
let failures = copy st.failures;
219219
let failures = vec::map(failures, |test| test.name);
220-
let failures = sort::merge_sort(str::le, failures);
220+
let failures = sort::merge_sort(|x, y| str::le(*x, *y), failures);
221221
for vec::each(failures) |name| {
222222
st.out.write_line(fmt!(" %s", name));
223223
}
@@ -371,7 +371,7 @@ fn filter_tests(opts: test_opts,
371371
// Sort the tests alphabetically
372372
filtered = {
373373
pure fn lteq(t1: &test_desc, t2: &test_desc) -> bool {
374-
str::le(&t1.name, &t2.name)
374+
str::le(t1.name, t2.name)
375375
}
376376
sort::merge_sort(lteq, filtered)
377377
};

branches/incoming/src/libsyntax/ast_util.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,11 @@ pure fn binop_to_method_name(op: binop) -> Option<~str> {
106106
shl => return Some(~"shl"),
107107
shr => return Some(~"shr"),
108108
lt => return Some(~"lt"),
109+
le => return Some(~"le"),
110+
ge => return Some(~"ge"),
111+
gt => return Some(~"gt"),
109112
eq => return Some(~"eq"),
110-
and | or | le | ne | ge | gt => return None
113+
and | or | ne => return None
111114
}
112115
}
113116

branches/incoming/src/rustc/middle/resolve.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4341,7 +4341,8 @@ struct Resolver {
43414341
self.add_fixed_trait_for_expr(expr.id,
43424342
self.lang_items.shr_trait);
43434343
}
4344-
expr_binary(lt, _, _) => {
4344+
expr_binary(lt, _, _) | expr_binary(le, _, _) |
4345+
expr_binary(ge, _, _) | expr_binary(gt, _, _) => {
43454346
self.add_fixed_trait_for_expr(expr.id,
43464347
self.lang_items.ord_trait);
43474348
}

0 commit comments

Comments
 (0)