Skip to content

Commit 3b1f5e3

Browse files
committed
Use iter::zip in library/
1 parent b362958 commit 3b1f5e3

File tree

8 files changed

+18
-15
lines changed

8 files changed

+18
-15
lines changed

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
// that the feature-gate isn't enabled. Ideally, it wouldn't check for the feature gate for docs
109109
// from other crates, but since this can only appear for lang items, it doesn't seem worth fixing.
110110
#![feature(intra_doc_pointers)]
111+
#![feature(iter_zip)]
111112
#![feature(lang_items)]
112113
#![feature(layout_for_ptr)]
113114
#![feature(maybe_uninit_ref)]

library/alloc/src/vec/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use core::convert::TryFrom;
5858
use core::fmt;
5959
use core::hash::{Hash, Hasher};
6060
use core::intrinsics::{arith_offset, assume};
61-
use core::iter::FromIterator;
61+
use core::iter::{self, FromIterator};
6262
use core::marker::PhantomData;
6363
use core::mem::{self, ManuallyDrop, MaybeUninit};
6464
use core::ops::{self, Index, IndexMut, Range, RangeBounds};
@@ -2268,11 +2268,8 @@ impl<T: Clone, A: Allocator> ExtendFromWithinSpec for Vec<T, A> {
22682268
// - caller guaratees that src is a valid index
22692269
let to_clone = unsafe { this.get_unchecked(src) };
22702270

2271-
to_clone
2272-
.iter()
2273-
.cloned()
2274-
.zip(spare.iter_mut())
2275-
.map(|(src, dst)| dst.write(src))
2271+
iter::zip(to_clone, spare)
2272+
.map(|(src, dst)| dst.write(src.clone()))
22762273
// Note:
22772274
// - Element was just initialized with `MaybeUninit::write`, so it's ok to increace len
22782275
// - len is increased after each element to prevent leaks (see issue #82533)

library/core/src/array/iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::{
44
fmt,
5-
iter::{ExactSizeIterator, FusedIterator, TrustedLen, TrustedRandomAccess},
5+
iter::{self, ExactSizeIterator, FusedIterator, TrustedLen, TrustedRandomAccess},
66
mem::{self, MaybeUninit},
77
ops::Range,
88
ptr,
@@ -215,7 +215,7 @@ impl<T: Clone, const N: usize> Clone for IntoIter<T, N> {
215215
let mut new = Self { data: MaybeUninit::uninit_array(), alive: 0..0 };
216216

217217
// Clone all alive elements.
218-
for (src, dst) in self.as_slice().iter().zip(&mut new.data) {
218+
for (src, dst) in iter::zip(self.as_slice(), &mut new.data) {
219219
// Write a clone into the new array, then update its alive range.
220220
// If cloning panics, we'll correctly drop the previous items.
221221
dst.write(src.clone());

library/core/src/fmt/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use crate::cell::{Cell, Ref, RefCell, RefMut, UnsafeCell};
66
use crate::char::EscapeDebugExtArgs;
7+
use crate::iter;
78
use crate::marker::PhantomData;
89
use crate::mem;
910
use crate::num::flt2dec;
@@ -1088,7 +1089,7 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
10881089
match args.fmt {
10891090
None => {
10901091
// We can use default formatting parameters for all arguments.
1091-
for (arg, piece) in args.args.iter().zip(args.pieces.iter()) {
1092+
for (arg, piece) in iter::zip(args.args, args.pieces) {
10921093
formatter.buf.write_str(*piece)?;
10931094
(arg.formatter)(arg.value, &mut formatter)?;
10941095
idx += 1;
@@ -1097,7 +1098,7 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
10971098
Some(fmt) => {
10981099
// Every spec has a corresponding argument that is preceded by
10991100
// a string piece.
1100-
for (arg, piece) in fmt.iter().zip(args.pieces.iter()) {
1101+
for (arg, piece) in iter::zip(fmt, args.pieces) {
11011102
formatter.buf.write_str(*piece)?;
11021103
// SAFETY: arg and args.args come from the same Arguments,
11031104
// which guarantees the indexes are always within bounds.

library/core/src/num/bignum.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,12 @@ macro_rules! define_bignum {
181181
/// Adds `other` to itself and returns its own mutable reference.
182182
pub fn add<'a>(&'a mut self, other: &$name) -> &'a mut $name {
183183
use crate::cmp;
184+
use crate::iter;
184185
use crate::num::bignum::FullOps;
185186

186187
let mut sz = cmp::max(self.size, other.size);
187188
let mut carry = false;
188-
for (a, b) in self.base[..sz].iter_mut().zip(&other.base[..sz]) {
189+
for (a, b) in iter::zip(&mut self.base[..sz], &other.base[..sz]) {
189190
let (c, v) = (*a).full_add(*b, carry);
190191
*a = v;
191192
carry = c;
@@ -219,11 +220,12 @@ macro_rules! define_bignum {
219220
/// Subtracts `other` from itself and returns its own mutable reference.
220221
pub fn sub<'a>(&'a mut self, other: &$name) -> &'a mut $name {
221222
use crate::cmp;
223+
use crate::iter;
222224
use crate::num::bignum::FullOps;
223225

224226
let sz = cmp::max(self.size, other.size);
225227
let mut noborrow = true;
226-
for (a, b) in self.base[..sz].iter_mut().zip(&other.base[..sz]) {
228+
for (a, b) in iter::zip(&mut self.base[..sz], &other.base[..sz]) {
227229
let (c, v) = (*a).full_add(!*b, noborrow);
228230
*a = v;
229231
noborrow = c;

library/core/src/slice/ascii.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Operations on ASCII `[u8]`.
22
3+
use crate::iter;
34
use crate::mem;
45

56
#[lang = "slice_u8"]
@@ -19,7 +20,7 @@ impl [u8] {
1920
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
2021
#[inline]
2122
pub fn eq_ignore_ascii_case(&self, other: &[u8]) -> bool {
22-
self.len() == other.len() && self.iter().zip(other).all(|(a, b)| a.eq_ignore_ascii_case(b))
23+
self.len() == other.len() && iter::zip(self, other).all(|(a, b)| a.eq_ignore_ascii_case(b))
2324
}
2425

2526
/// Converts this slice to its ASCII upper case equivalent in-place.

library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@
278278
#![feature(integer_atomics)]
279279
#![feature(into_future)]
280280
#![feature(intra_doc_pointers)]
281+
#![feature(iter_zip)]
281282
#![feature(lang_items)]
282283
#![feature(link_args)]
283284
#![feature(linkage)]

library/std/src/sys/unix/ext/net/addr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::ffi::OsStr;
22
use crate::os::unix::ffi::OsStrExt;
33
use crate::path::Path;
44
use crate::sys::cvt;
5-
use crate::{ascii, fmt, io, mem};
5+
use crate::{ascii, fmt, io, iter, mem};
66

77
// FIXME(#43348): Make libc adapt #[doc(cfg(...))] so we don't need these fake definitions here?
88
#[cfg(not(unix))]
@@ -41,7 +41,7 @@ pub(super) unsafe fn sockaddr_un(path: &Path) -> io::Result<(libc::sockaddr_un,
4141
&"path must be shorter than SUN_LEN",
4242
));
4343
}
44-
for (dst, src) in addr.sun_path.iter_mut().zip(bytes.iter()) {
44+
for (dst, src) in iter::zip(&mut addr.sun_path, bytes) {
4545
*dst = *src as libc::c_char;
4646
}
4747
// null byte for pathname addresses is already there because we zeroed the

0 commit comments

Comments
 (0)