Skip to content

Commit 845ff65

Browse files
committed
auto merge of #16203 : Gankro/rust/vec_flow, r=alexcrichton
fixes #16200
2 parents 9a3b25f + d9b2e6b commit 845ff65

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/libcollections/vec.rs

+7-1
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(|| {

0 commit comments

Comments
 (0)