File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
branches/snap-stage3/src/libcore Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
- refs/heads/snap-stage3: 3698ea7e54c46cfde377f95782710ee5e19876d3
4
+ refs/heads/snap-stage3: 85b82c763bfbfd5de59f4c6b026dca58f3ba4687
5
5
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
Original file line number Diff line number Diff line change @@ -116,6 +116,19 @@ totalord_impl!(i64)
116
116
totalord_impl ! ( int)
117
117
totalord_impl ! ( uint)
118
118
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
+
119
132
/**
120
133
* Trait for values that can be compared for a sort-order.
121
134
*
@@ -184,6 +197,8 @@ pub fn max<T:Ord>(v1: T, v2: T) -> T {
184
197
185
198
#[ cfg( test) ]
186
199
mod test {
200
+ use super :: lexical_ordering;
201
+
187
202
#[ test]
188
203
fn test_int_totalord ( ) {
189
204
assert_eq ! ( 5 . cmp( & 10 ) , Less ) ;
@@ -204,4 +219,16 @@ mod test {
204
219
assert ! ( Less < Equal ) ;
205
220
assert_eq ! ( Greater . cmp( & Less ) , Greater ) ;
206
221
}
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
+ }
207
234
}
You can’t perform that action at this time.
0 commit comments