Skip to content

Commit b85e2e4

Browse files
committed
Update splice impl
1 parent 2111aff commit b85e2e4

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/libcollections/string.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1421,8 +1421,16 @@ impl String {
14211421
// Because the range removal happens in Drop, if the Splice iterator is leaked,
14221422
// the removal will not happen.
14231423
let len = self.len();
1424-
let start = *range.start().unwrap_or(&0);
1425-
let end = *range.end().unwrap_or(&len);
1424+
let start = match range.start() {
1425+
Included(&n) => n,
1426+
Excluded(&n) => n + 1,
1427+
Unbounded => 0,
1428+
};
1429+
let end = match range.end() {
1430+
Included(&n) => n + 1,
1431+
Excluded(&n) => n,
1432+
Unbounded => len,
1433+
};
14261434

14271435
// Take out two simultaneous borrows. The &mut String won't be accessed
14281436
// until iteration is over, in Drop.
@@ -2210,6 +2218,7 @@ impl<'a> FusedIterator for Drain<'a> {}
22102218
///
22112219
/// [`splice()`]: struct.String.html#method.splice
22122220
/// [`String`]: struct.String.html
2221+
#[derive(Debug)]
22132222
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
22142223
pub struct Splice<'a, 'b> {
22152224
/// Will be used as &'a mut String in the destructor

src/libcollections/vec.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,14 @@ impl<'a, T> InPlace<T> for PlaceBack<'a, T> {
23942394
}
23952395

23962396

2397-
/// A splicing iterator for `Vec<T>`. See the [`Vec::splice`](struct.Vec.html#method.splice) method.
2397+
/// A splicing iterator for `Vec`.
2398+
///
2399+
/// This struct is created by the [`splice()`] method on [`Vec`]. See its
2400+
/// documentation for more.
2401+
///
2402+
/// [`splice()`]: struct.Vec.html#method.splice
2403+
/// [`Vec`]: struct.Vec.html
2404+
#[derive(Debug)]
23982405
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
23992406
pub struct Splice<'a, I: Iterator + 'a> {
24002407
drain: Drain<'a, I::Item>,
@@ -2434,7 +2441,7 @@ impl<'a, I: Iterator> Drop for Splice<'a, I> {
24342441

24352442
unsafe {
24362443
if self.drain.tail_len == 0 {
2437-
let vec = &mut *self.drain.vec;
2444+
let vec = &mut *self.drain.vec.as_mut_ptr();
24382445
vec.extend(self.replace_with.by_ref());
24392446
return
24402447
}
@@ -2476,7 +2483,7 @@ impl<'a, T> Drain<'a, T> {
24762483
/// Fill that range as much as possible with new elements from the `replace_with` iterator.
24772484
/// Return whether we filled the entire range. (`replace_with.next()` didn’t return `None`.)
24782485
unsafe fn fill<I: Iterator<Item=T>>(&mut self, replace_with: &mut I) -> bool {
2479-
let vec = &mut *self.vec;
2486+
let vec = &mut *self.vec.as_mut_ptr();
24802487
let range_start = vec.len;
24812488
let range_end = self.tail_start;
24822489
let range_slice = slice::from_raw_parts_mut(
@@ -2496,7 +2503,7 @@ impl<'a, T> Drain<'a, T> {
24962503

24972504
/// Make room for inserting more elements before the tail.
24982505
unsafe fn move_tail(&mut self, extra_capacity: usize) {
2499-
let vec = &mut *self.vec;
2506+
let vec = &mut *self.vec.as_mut_ptr();
25002507
let used_capacity = self.tail_start + self.tail_len;
25012508
vec.buf.reserve(used_capacity, extra_capacity);
25022509

0 commit comments

Comments
 (0)