Skip to content

Commit 093c526

Browse files
author
Julian Orth
committed
fixup
1 parent 2c6536a commit 093c526

File tree

3 files changed

+39
-36
lines changed

3 files changed

+39
-36
lines changed

src/libcollections/binary_heap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ impl<T: Ord> BinaryHeap<T> {
553553
#[inline]
554554
#[unstable(feature = "collections",
555555
reason = "matches collection reform specification, waiting for dust to settle")]
556-
pub fn drain<'a>(&'a mut self) -> Drain<'a, T> {
556+
pub fn drain(&mut self) -> Drain<T> {
557557
Drain { iter: self.data.drain(..) }
558558
}
559559

src/libcollections/string.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -671,24 +671,25 @@ impl String {
671671
self.vec.clear()
672672
}
673673

674-
/// Creates a draining iterator that clears the specified range in the String
675-
/// and iterates over the characters contained in the range.
674+
/// Creates a draining iterator that clears the specified byte-range in the String
675+
/// and iterates over the characters contained in the range, backshifting the
676+
/// remaining bytes.
676677
///
677678
/// # Example
678679
///
679680
/// ```
680-
/// let mut s = "Hello World!".to_string();
681-
/// let s2: String = s.drain(6..11).collect();
681+
/// let mut s = "Hello Wörld!".to_string();
682+
/// let s2: String = s.drain(6..12).collect();
682683
/// assert_eq!(s, "Hello !");
683-
/// assert_eq!(s2, "World");
684+
/// assert_eq!(s2, "Wörld");
684685
/// ```
685686
///
686687
/// # Panics
687688
///
688689
/// Panics if the range is decreasing, if the upper bound is larger than the
689690
/// length of the String, or if the start and the end of the range don't lie on
690691
/// character boundaries.
691-
pub fn drain<'a, T: DrainRange>(&'a mut self, range: T) -> CharDrain<'a> {
692+
pub fn drain<'a, T: DrainRange>(&'a mut self, range: T) -> Drain<'a> {
692693
range.drain(self)
693694
}
694695
}
@@ -697,19 +698,19 @@ impl String {
697698
///
698699
/// See the documentation of `String::drain`.
699700
pub trait DrainRange {
700-
fn drain<'a>(&self, s: &'a mut String) -> CharDrain<'a>;
701+
fn drain<'a>(&self, s: &'a mut String) -> Drain<'a>;
701702
}
702703

703704
impl DrainRange for Range<usize> {
704-
fn drain<'a>(&self, s: &'a mut String) -> CharDrain<'a> {
705+
fn drain<'a>(&self, s: &'a mut String) -> Drain<'a> {
705706
assert!(self.start <= self.end, "Range not increasing");
706707
assert!(self.end <= s.len(), "Range out of bounds");
707708
unsafe {
708709
let slice = mem::transmute::<&str, &'static str>(&s[self.start..self.end]);
709710
let tail = s.len() - self.end;
710711
s.as_mut_vec().set_len(tail + self.start);
711712
let ptr = s.as_mut_vec().as_mut_ptr();
712-
CharDrain {
713+
Drain {
713714
tail: tail,
714715
start: ptr.offset(self.start as isize),
715716
end: ptr.offset(self.end as isize),
@@ -720,43 +721,43 @@ impl DrainRange for Range<usize> {
720721
}
721722

722723
impl DrainRange for RangeFrom<usize> {
723-
fn drain<'a>(&self, s: &'a mut String) -> CharDrain<'a> {
724+
fn drain<'a>(&self, s: &'a mut String) -> Drain<'a> {
724725
assert!(self.start <= s.len(), "Range out of bounds");
725726
(self.start..s.len()).drain(s)
726727
}
727728
}
728729

729730
impl DrainRange for RangeTo<usize> {
730-
fn drain<'a>(&self, s: &'a mut String) -> CharDrain<'a> {
731+
fn drain<'a>(&self, s: &'a mut String) -> Drain<'a> {
731732
(0..self.end).drain(s)
732733
}
733734
}
734735

735736
impl DrainRange for RangeFull {
736-
fn drain<'a>(&self, s: &'a mut String) -> CharDrain<'a> {
737+
fn drain<'a>(&self, s: &'a mut String) -> Drain<'a> {
737738
(0..s.len()).drain(s)
738739
}
739740
}
740741

741742
impl DrainRange for usize {
742-
fn drain<'a>(&self, s: &'a mut String) -> CharDrain<'a> {
743+
fn drain<'a>(&self, s: &'a mut String) -> Drain<'a> {
743744
(*self..*self+1).drain(s)
744745
}
745746
}
746747

747748
/// An iterator that drains part of string.
748749
#[unsafe_no_drop_flag]
749-
pub struct CharDrain<'a> {
750+
pub struct Drain<'a> {
750751
tail: usize,
751-
start: *mut u8,
752-
end: *mut u8,
752+
start: *const u8,
753+
end: *const u8,
753754
chars: Chars<'a>,
754755
}
755756

756-
unsafe impl<'a> Sync for CharDrain<'a> {}
757-
unsafe impl<'a> Send for CharDrain<'a> {}
757+
unsafe impl<'a> Sync for Drain<'a> {}
758+
unsafe impl<'a> Send for Drain<'a> {}
758759

759-
impl<'a> Iterator for CharDrain<'a> {
760+
impl<'a> Iterator for Drain<'a> {
760761
type Item = char;
761762

762763
#[inline]
@@ -770,20 +771,20 @@ impl<'a> Iterator for CharDrain<'a> {
770771
}
771772
}
772773

773-
impl<'a> DoubleEndedIterator for CharDrain<'a> {
774+
impl<'a> DoubleEndedIterator for Drain<'a> {
774775
#[inline]
775776
fn next_back(&mut self) -> Option<char> {
776777
self.chars.next_back()
777778
}
778779
}
779780

780781
#[unsafe_destructor]
781-
impl<'a> Drop for CharDrain<'a> {
782+
impl<'a> Drop for Drain<'a> {
782783
fn drop(&mut self) {
783784
// self.start == null if drop has already been called, so we can use
784785
// #[unsafe_no_drop_flag].
785786
if !self.start.is_null() {
786-
unsafe { ptr::copy(self.start, self.end, self.tail); }
787+
unsafe { ptr::copy(self.start as *mut _, self.end, self.tail); }
787788
}
788789
}
789790
}
@@ -1561,9 +1562,9 @@ mod tests {
15611562

15621563
#[test]
15631564
fn test_drain() {
1564-
let mut s = "Hello World!".to_string();
1565-
let s2: String = s.drain(6..11).collect();
1565+
let mut s = "Hello Wörld!".to_string();
1566+
let s2: String = s.drain(6..12).collect();
15661567
assert_eq!(s, "Hello !");
1567-
assert_eq!(s2, "World");
1568+
assert_eq!(s2, "Wörld");
15681569
}
15691570
}

src/libcollections/vec.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,10 +1755,10 @@ impl DrainRange for Range<usize> {
17551755
unsafe {
17561756
let tail = vec.len() - self.end;
17571757
vec.set_len(tail + self.start);
1758-
let ptr = vec.as_mut_ptr();
1758+
let ptr = vec.as_ptr();
17591759
let (start, end) = if mem::size_of::<T>() == 0 {
17601760
// make sure that start is not null
1761-
((self.start + 1) as *mut T, (self.end + 1) as *mut T)
1761+
((self.start + 1) as *const T, (self.end + 1) as *const T)
17621762
} else {
17631763
(ptr.offset(self.start as isize), ptr.offset(self.end as isize))
17641764
};
@@ -1768,7 +1768,8 @@ impl DrainRange for Range<usize> {
17681768
end: end,
17691769
left: start,
17701770
right: end,
1771-
marker: PhantomData,
1771+
marker1: PhantomData,
1772+
marker2: PhantomData,
17721773
}
17731774
}
17741775
}
@@ -1803,13 +1804,14 @@ impl DrainRange for usize {
18031804
#[unsafe_no_drop_flag]
18041805
#[unstable(feature = "collections",
18051806
reason = "recently added as part of collections reform 2")]
1806-
pub struct Drain<'a, T:'a> {
1807+
pub struct Drain<'a, T: 'a> {
18071808
tail: usize,
1808-
start: *mut T,
1809-
end: *mut T,
1810-
left: *mut T,
1811-
right: *mut T,
1812-
marker: PhantomData<&'a T>,
1809+
start: *const T,
1810+
end: *const T,
1811+
left: *const T,
1812+
right: *const T,
1813+
marker1: PhantomData<&'a ()>,
1814+
marker2: PhantomData<T>,
18131815
}
18141816

18151817
unsafe impl<'a, T: Sync> Sync for Drain<'a, T> {}
@@ -1890,7 +1892,7 @@ impl<'a, T> Drop for Drain<'a, T> {
18901892
for _x in self.by_ref() {}
18911893

18921894
if mem::size_of::<T>() > 0 {
1893-
unsafe { ptr::copy(self.start, self.end, self.tail); }
1895+
unsafe { ptr::copy(self.start as *mut _, self.end, self.tail); }
18941896
}
18951897
}
18961898
}

0 commit comments

Comments
 (0)