Rollup merge of #82917 - cuviper:iter-zip, r=m-ou-se
Add function core::iter::zip This makes it a little easier to `zip` iterators: ```rust for (x, y) in zip(xs, ys) {} // vs. for (x, y) in xs.into_iter().zip(ys) {} ``` You can `zip(&mut xs, &ys)` for the conventional `iter_mut()` and `iter()`, respectively. This can also support arbitrary nesting, where it's easier to see the item layout than with arbitrary `zip` chains: ```rust for ((x, y), z) in zip(zip(xs, ys), zs) {} for (x, (y, z)) in zip(xs, zip(ys, zs)) {} // vs. for ((x, y), z) in xs.into_iter().zip(ys).zip(xz) {} for (x, (y, z)) in xs.into_iter().zip((ys.into_iter().zip(xz)) {} ``` It may also format more nicely, especially when the first iterator is a longer chain of methods -- for example: ```rust iter::zip( trait_ref.substs.types().skip(1), impl_trait_ref.substs.types().skip(1), ) // vs. trait_ref .substs .types() .skip(1) .zip(impl_trait_ref.substs.types().skip(1)) ``` This replaces the tuple-pair `IntoIterator` in #78204. There is prior art for the utility of this in [`itertools::zip`]. [`itertools::zip`]: https://docs.rs/itertools/0.10.0/itertools/fn.zip.html
This commit is contained in:
commit
b2e254318d
111 changed files with 310 additions and 256 deletions
|
@ -2,6 +2,7 @@
|
|||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(decl_macro)]
|
||||
#![feature(destructuring_assignment)]
|
||||
#![feature(iter_zip)]
|
||||
#![cfg_attr(bootstrap, feature(or_patterns))]
|
||||
#![feature(proc_macro_diagnostic)]
|
||||
#![feature(proc_macro_internals)]
|
||||
|
|
|
@ -116,6 +116,8 @@ use rustc_span::{symbol::MacroRulesNormalizedIdent, MultiSpan, Span};
|
|||
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use std::iter;
|
||||
|
||||
/// Stack represented as linked list.
|
||||
///
|
||||
/// Those are used for environments because they grow incrementally and are not mutable.
|
||||
|
@ -204,7 +206,7 @@ pub(super) fn check_meta_variables(
|
|||
sess.span_diagnostic.span_bug(span, "length mismatch between LHSes and RHSes")
|
||||
}
|
||||
let mut valid = true;
|
||||
for (lhs, rhs) in lhses.iter().zip(rhses.iter()) {
|
||||
for (lhs, rhs) in iter::zip(lhses, rhses) {
|
||||
let mut binders = Binders::default();
|
||||
check_binders(sess, node_id, lhs, &Stack::Empty, &mut binders, &Stack::Empty, &mut valid);
|
||||
check_occurrences(sess, node_id, rhs, &Stack::Empty, &binders, &Stack::Empty, &mut valid);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue