Skip to content

Commit 5bf4f7d

Browse files
implement remove in terms of try_remove
1 parent e13fe23 commit 5bf4f7d

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

library/alloc/src/vec/mod.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,26 +2200,7 @@ impl<T, A: Allocator> Vec<T, A> {
22002200
panic!("removal index (is {index}) should be < len (is {len})");
22012201
}
22022202

2203-
let len = self.len();
2204-
if index >= len {
2205-
assert_failed(index, len);
2206-
}
2207-
unsafe {
2208-
// infallible
2209-
let ret;
2210-
{
2211-
// the place we are taking from.
2212-
let ptr = self.as_mut_ptr().add(index);
2213-
// copy it out, unsafely having a copy of the value on
2214-
// the stack and in the vector at the same time.
2215-
ret = ptr::read(ptr);
2216-
2217-
// Shift everything down to fill in that spot.
2218-
ptr::copy(ptr.add(1), ptr, len - index - 1);
2219-
}
2220-
self.set_len(len - 1);
2221-
ret
2222-
}
2203+
self.try_remove(index).unwrap_or_else(assert_failed)
22232204
}
22242205

22252206
/// Remove and return the element at position `index` within the vector,

0 commit comments

Comments
 (0)