Skip to content

Commit 69a699e

Browse files
committed
---
yaml --- r: 56077 b: refs/heads/auto c: 85b82c7 h: refs/heads/master i: 56075: 657187a v: v3
1 parent ecd853d commit 69a699e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: 3698ea7e54c46cfde377f95782710ee5e19876d3
17+
refs/heads/auto: 85b82c763bfbfd5de59f4c6b026dca58f3ba4687
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/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)