Skip to content

Commit 795e687

Browse files
committed
---
yaml --- r: 154047 b: refs/heads/try2 c: 8b9ab0d h: refs/heads/master i: 154045: 69a4712 154043: 41f1d3e 154039: 365ca54 154031: 6449434 154015: 877b5ce 153983: 096415e v: v3
1 parent 49efb29 commit 795e687

File tree

6 files changed

+50
-4
lines changed

6 files changed

+50
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: c41c1edf3b196c4b36fa4ab2fb205cc002f2546d
8+
refs/heads/try2: 8b9ab0d91243e2e616275f09410bc82018892f14
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/guide.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,6 @@ you create a new type that's a synonym for another one:
10601060

10611061
```
10621062
struct Inches(int);
1063-
struct Centimeters(int);
10641063
10651064
let length = Inches(10);
10661065

branches/try2/src/libcollections/vec.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ impl<T> Vec<T> {
964964
#[inline]
965965
pub fn swap_remove(&mut self, index: uint) -> Option<T> {
966966
let length = self.len();
967-
if index < length - 1 {
967+
if length > 0 && index < length - 1 {
968968
self.as_mut_slice().swap(index, length - 1);
969969
} else if index >= length {
970970
return None
@@ -2003,6 +2003,12 @@ mod tests {
20032003
let _ = vec[3];
20042004
}
20052005

2006+
#[test]
2007+
fn test_swap_remove_empty() {
2008+
let mut vec: Vec<uint> = vec!();
2009+
assert_eq!(vec.swap_remove(0), None);
2010+
}
2011+
20062012
#[bench]
20072013
fn bench_new(b: &mut Bencher) {
20082014
b.iter(|| {

branches/try2/src/libcore/cmp.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,40 @@ pub enum Ordering {
100100
Greater = 1i,
101101
}
102102

103+
impl Ordering {
104+
/// Reverse the `Ordering`, so that `Less` becomes `Greater` and
105+
/// vice versa.
106+
///
107+
/// # Example
108+
///
109+
/// ```rust
110+
/// assert_eq!(Less.reverse(), Greater);
111+
/// assert_eq!(Equal.reverse(), Equal);
112+
/// assert_eq!(Greater.reverse(), Less);
113+
///
114+
///
115+
/// let mut data = &mut [2u, 10, 5, 8];
116+
///
117+
/// // sort the array from largest to smallest.
118+
/// data.sort_by(|a, b| a.cmp(b).reverse());
119+
///
120+
/// assert_eq!(data, &mut [10u, 8, 5, 2]);
121+
/// ```
122+
#[inline]
123+
#[experimental]
124+
pub fn reverse(self) -> Ordering {
125+
unsafe {
126+
// this compiles really nicely (to a single instruction);
127+
// an explicit match has a pile of branches and
128+
// comparisons.
129+
//
130+
// NB. it is safe because of the explicit discriminants
131+
// given above.
132+
::mem::transmute::<_, Ordering>(-(self as i8))
133+
}
134+
}
135+
}
136+
103137
/// Trait for types that form a [total order](
104138
/// https://en.wikipedia.org/wiki/Total_order).
105139
///

branches/try2/src/libcoretest/cmp.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ fn test_mut_int_totalord() {
2828
assert_eq!((&mut 12i).cmp(&&mut -5), Greater);
2929
}
3030

31+
#[test]
32+
fn test_ordering_reverse() {
33+
assert_eq!(Less.reverse(), Greater);
34+
assert_eq!(Equal.reverse(), Equal);
35+
assert_eq!(Greater.reverse(), Less);
36+
}
37+
3138
#[test]
3239
fn test_ordering_order() {
3340
assert!(Less < Equal);

branches/try2/src/libtime/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub fn tzset() {
203203

204204
/// Holds a calendar date and time broken down into its components (year, month, day, and so on),
205205
/// also called a broken-down time value.
206-
#[deriving(Clone, PartialEq, Show)]
206+
#[deriving(Clone, PartialEq, Eq, Show)]
207207
pub struct Tm {
208208
/// Seconds after the minute - [0, 60]
209209
pub tm_sec: i32,

0 commit comments

Comments
 (0)