mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Update expressions where we can use array's IntoIterator implementation
This commit is contained in:
parent
01d4d46f66
commit
507d97b26e
@ -551,19 +551,13 @@ const LEN: usize = 16384;
|
||||
#[bench]
|
||||
fn bench_chain_collect(b: &mut Bencher) {
|
||||
let data = black_box([0; LEN]);
|
||||
b.iter(|| data.iter().cloned().chain([1].iter().cloned()).collect::<Vec<_>>());
|
||||
b.iter(|| data.iter().cloned().chain([1]).collect::<Vec<_>>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_chain_chain_collect(b: &mut Bencher) {
|
||||
let data = black_box([0; LEN]);
|
||||
b.iter(|| {
|
||||
data.iter()
|
||||
.cloned()
|
||||
.chain([1].iter().cloned())
|
||||
.chain([2].iter().cloned())
|
||||
.collect::<Vec<_>>()
|
||||
});
|
||||
b.iter(|| data.iter().cloned().chain([1]).chain([2]).collect::<Vec<_>>());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
|
@ -921,7 +921,7 @@ impl<T, A: Allocator> Vec<T, A> {
|
||||
///
|
||||
/// ```
|
||||
/// let mut vec = Vec::with_capacity(10);
|
||||
/// vec.extend([1, 2, 3].iter().cloned());
|
||||
/// vec.extend([1, 2, 3]);
|
||||
/// assert_eq!(vec.capacity(), 10);
|
||||
/// vec.shrink_to_fit();
|
||||
/// assert!(vec.capacity() >= 3);
|
||||
@ -950,7 +950,7 @@ impl<T, A: Allocator> Vec<T, A> {
|
||||
/// ```
|
||||
/// #![feature(shrink_to)]
|
||||
/// let mut vec = Vec::with_capacity(10);
|
||||
/// vec.extend([1, 2, 3].iter().cloned());
|
||||
/// vec.extend([1, 2, 3]);
|
||||
/// assert_eq!(vec.capacity(), 10);
|
||||
/// vec.shrink_to(4);
|
||||
/// assert!(vec.capacity() >= 4);
|
||||
@ -984,7 +984,7 @@ impl<T, A: Allocator> Vec<T, A> {
|
||||
///
|
||||
/// ```
|
||||
/// let mut vec = Vec::with_capacity(10);
|
||||
/// vec.extend([1, 2, 3].iter().cloned());
|
||||
/// vec.extend([1, 2, 3]);
|
||||
///
|
||||
/// assert_eq!(vec.capacity(), 10);
|
||||
/// let slice = vec.into_boxed_slice();
|
||||
@ -2586,7 +2586,7 @@ impl<T, A: Allocator> Vec<T, A> {
|
||||
/// ```
|
||||
/// let mut v = vec![1, 2, 3];
|
||||
/// let new = [7, 8];
|
||||
/// let u: Vec<_> = v.splice(..2, new.iter().cloned()).collect();
|
||||
/// let u: Vec<_> = v.splice(..2, new).collect();
|
||||
/// assert_eq!(v, &[7, 8, 3]);
|
||||
/// assert_eq!(u, &[1, 2]);
|
||||
/// ```
|
||||
|
@ -14,7 +14,7 @@ use super::{Drain, Vec};
|
||||
/// ```
|
||||
/// let mut v = vec![0, 1, 2];
|
||||
/// let new = [7, 8];
|
||||
/// let iter: std::vec::Splice<_> = v.splice(1.., new.iter().cloned());
|
||||
/// let iter: std::vec::Splice<_> = v.splice(1.., new);
|
||||
/// ```
|
||||
#[derive(Debug)]
|
||||
#[stable(feature = "vec_splice", since = "1.21.0")]
|
||||
|
@ -793,7 +793,7 @@ fn test_drain_leak() {
|
||||
fn test_splice() {
|
||||
let mut v = vec![1, 2, 3, 4, 5];
|
||||
let a = [10, 11, 12];
|
||||
v.splice(2..4, a.iter().cloned());
|
||||
v.splice(2..4, a);
|
||||
assert_eq!(v, &[1, 2, 10, 11, 12, 5]);
|
||||
v.splice(1..3, Some(20));
|
||||
assert_eq!(v, &[1, 20, 11, 12, 5]);
|
||||
@ -803,7 +803,7 @@ fn test_splice() {
|
||||
fn test_splice_inclusive_range() {
|
||||
let mut v = vec![1, 2, 3, 4, 5];
|
||||
let a = [10, 11, 12];
|
||||
let t1: Vec<_> = v.splice(2..=3, a.iter().cloned()).collect();
|
||||
let t1: Vec<_> = v.splice(2..=3, a).collect();
|
||||
assert_eq!(v, &[1, 2, 10, 11, 12, 5]);
|
||||
assert_eq!(t1, &[3, 4]);
|
||||
let t2: Vec<_> = v.splice(1..=2, Some(20)).collect();
|
||||
@ -816,7 +816,7 @@ fn test_splice_inclusive_range() {
|
||||
fn test_splice_out_of_bounds() {
|
||||
let mut v = vec![1, 2, 3, 4, 5];
|
||||
let a = [10, 11, 12];
|
||||
v.splice(5..6, a.iter().cloned());
|
||||
v.splice(5..6, a);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -824,7 +824,7 @@ fn test_splice_out_of_bounds() {
|
||||
fn test_splice_inclusive_out_of_bounds() {
|
||||
let mut v = vec![1, 2, 3, 4, 5];
|
||||
let a = [10, 11, 12];
|
||||
v.splice(5..=5, a.iter().cloned());
|
||||
v.splice(5..=5, a);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -848,7 +848,7 @@ fn test_splice_unbounded() {
|
||||
fn test_splice_forget() {
|
||||
let mut v = vec![1, 2, 3, 4, 5];
|
||||
let a = [10, 11, 12];
|
||||
std::mem::forget(v.splice(2..4, a.iter().cloned()));
|
||||
std::mem::forget(v.splice(2..4, a));
|
||||
assert_eq!(v, &[1, 2]);
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ impl char {
|
||||
/// ];
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// decode_utf16(v.iter().cloned())
|
||||
/// decode_utf16(v)
|
||||
/// .map(|r| r.map_err(|e| e.unpaired_surrogate()))
|
||||
/// .collect::<Vec<_>>(),
|
||||
/// vec![
|
||||
@ -82,7 +82,7 @@ impl char {
|
||||
/// ];
|
||||
///
|
||||
/// assert_eq!(
|
||||
/// decode_utf16(v.iter().cloned())
|
||||
/// decode_utf16(v)
|
||||
/// .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
|
||||
/// .collect::<String>(),
|
||||
/// "𝄞mus<75>ic<69>"
|
||||
|
@ -1,4 +1,4 @@
|
||||
use core::array::{self, IntoIter};
|
||||
use core::array;
|
||||
use core::convert::TryFrom;
|
||||
|
||||
#[test]
|
||||
|
@ -236,9 +236,7 @@ fn test_zip_trusted_random_access_composition() {
|
||||
fn test_double_ended_zip() {
|
||||
let xs = [1, 2, 3, 4, 5, 6];
|
||||
let ys = [1, 2, 3, 7];
|
||||
let a = xs.iter().cloned();
|
||||
let b = ys.iter().cloned();
|
||||
let mut it = a.zip(b);
|
||||
let mut it = xs.iter().cloned().zip(ys);
|
||||
assert_eq!(it.next(), Some((1, 1)));
|
||||
assert_eq!(it.next(), Some((2, 2)));
|
||||
assert_eq!(it.next_back(), Some((4, 7)));
|
||||
|
Loading…
Reference in New Issue
Block a user