Auto merge of #31704 - tbu-:pr_vec_into_iter_clone, r=aturon
This commit is contained in:
commit
c8fc4817dc
@ -59,9 +59,10 @@
|
||||
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
use alloc::raw_vec::RawVec;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::heap::EMPTY;
|
||||
use alloc::raw_vec::RawVec;
|
||||
use borrow::ToOwned;
|
||||
use core::cmp::Ordering;
|
||||
use core::fmt;
|
||||
use core::hash::{self, Hash};
|
||||
@ -1633,6 +1634,15 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> ExactSizeIterator for IntoIter<T> {}
|
||||
|
||||
#[stable(feature = "vec_into_iter_clone", since = "1.8.0")]
|
||||
impl<T: Clone> Clone for IntoIter<T> {
|
||||
fn clone(&self) -> IntoIter<T> {
|
||||
unsafe {
|
||||
slice::from_raw_parts(self.ptr, self.len()).to_owned().into_iter()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T> Drop for IntoIter<T> {
|
||||
#[unsafe_destructor_blind_to_params]
|
||||
|
@ -467,6 +467,24 @@ fn test_into_iter_count() {
|
||||
assert_eq!(vec![1, 2, 3].into_iter().count(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_into_iter_clone() {
|
||||
fn iter_equal<I: Iterator<Item=i32>>(it: I, slice: &[i32]) {
|
||||
let v: Vec<i32> = it.collect();
|
||||
assert_eq!(&v[..], slice);
|
||||
}
|
||||
let mut it = vec![1, 2, 3].into_iter();
|
||||
iter_equal(it.clone(), &[1, 2, 3]);
|
||||
assert_eq!(it.next(), Some(1));
|
||||
let mut it = it.rev();
|
||||
iter_equal(it.clone(), &[3, 2]);
|
||||
assert_eq!(it.next(), Some(3));
|
||||
iter_equal(it.clone(), &[2]);
|
||||
assert_eq!(it.next(), Some(2));
|
||||
iter_equal(it.clone(), &[]);
|
||||
assert_eq!(it.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cow_from() {
|
||||
let borrowed: &[_] = &["borrowed", "(slice)"];
|
||||
|
Loading…
Reference in New Issue
Block a user