Skip to content

Commit 758e1d1

Browse files
committed
---
yaml --- r: 54683 b: refs/heads/snap-stage3 c: 2cb6974 h: refs/heads/master i: 54681: f597acf 54679: e36ff12 v: v3
1 parent a1fda9b commit 758e1d1

File tree

17 files changed

+1609
-792
lines changed

17 files changed

+1609
-792
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 8b74efaa7b584428a00812697d66a4449884e3e1
4+
refs/heads/snap-stage3: 2cb69748563f7b9ab94160943eea6ec787b27a4d
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/cmp.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ totalord_impl!(i64)
116116
totalord_impl!(int)
117117
totalord_impl!(uint)
118118

119+
/**
120+
Return `o1` if it is not `Equal`, otherwise `o2`. Simulates the
121+
lexical ordering on a type `(int, int)`.
122+
*/
123+
// used in deriving code in libsyntax
124+
#[inline(always)]
125+
pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering {
126+
match o1 {
127+
Equal => o2,
128+
_ => o1
129+
}
130+
}
131+
119132
/**
120133
* Trait for values that can be compared for a sort-order.
121134
*
@@ -184,6 +197,8 @@ pub fn max<T:Ord>(v1: T, v2: T) -> T {
184197

185198
#[cfg(test)]
186199
mod test {
200+
use super::lexical_ordering;
201+
187202
#[test]
188203
fn test_int_totalord() {
189204
assert_eq!(5.cmp(&10), Less);
@@ -204,4 +219,16 @@ mod test {
204219
assert!(Less < Equal);
205220
assert_eq!(Greater.cmp(&Less), Greater);
206221
}
222+
223+
#[test]
224+
fn test_lexical_ordering() {
225+
fn t(o1: Ordering, o2: Ordering, e: Ordering) {
226+
assert_eq!(lexical_ordering(o1, o2), e);
227+
}
228+
for [Less, Equal, Greater].each |&o| {
229+
t(Less, o, Less);
230+
t(Equal, o, o);
231+
t(Greater, o, Greater);
232+
}
233+
}
207234
}

0 commit comments

Comments
 (0)