about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-08-03 11:36:07 +0000
committerbors <bors@rust-lang.org>2014-08-03 11:36:07 +0000
commit845ff6567fc9e5cb35a61aa77de79343cdb125d7 (patch)
tree841f2f96bb58cbdd1ff1433552f209b0f8dd516b
parent9a3b25fa9885e34213874dc63e9c436abc2a4a66 (diff)
parentd9b2e6b74fb0f8b4320c61d78dc5e07a8d3123b5 (diff)
downloadrust-845ff6567fc9e5cb35a61aa77de79343cdb125d7.tar.gz
rust-845ff6567fc9e5cb35a61aa77de79343cdb125d7.zip
auto merge of #16203 : Gankro/rust/vec_flow, r=alexcrichton
fixes #16200
-rw-r--r--src/libcollections/vec.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs
index a0c92887c43..6618906cf69 100644
--- a/src/libcollections/vec.rs
+++ b/src/libcollections/vec.rs
@@ -964,7 +964,7 @@ impl<T> Vec<T> {
     #[inline]
     pub fn swap_remove(&mut self, index: uint) -> Option<T> {
         let length = self.len();
-        if index < length - 1 {
+        if length > 0 && index < length - 1 {
             self.as_mut_slice().swap(index, length - 1);
         } else if index >= length {
             return None
@@ -2003,6 +2003,12 @@ mod tests {
         let _ = vec[3];
     }
 
+    #[test]
+    fn test_swap_remove_empty() {
+        let mut vec: Vec<uint> = vec!();
+        assert_eq!(vec.swap_remove(0), None);
+    }
+
     #[bench]
     fn bench_new(b: &mut Bencher) {
         b.iter(|| {