Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl<A, B> IntoIterator for (A, B) as Zip #78204

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_apfloat/src/ieee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2483,7 +2483,7 @@ mod sig {
pub(super) fn add(a: &mut [Limb], b: &[Limb], mut c: Limb) -> Limb {
assert!(c <= 1);

for (a, &b) in a.iter_mut().zip(b) {
for (a, &b) in (a, b) {
let (r, overflow) = a.overflowing_add(b);
let (r, overflow2) = r.overflowing_add(c);
*a = r;
Expand All @@ -2497,7 +2497,7 @@ mod sig {
pub(super) fn sub(a: &mut [Limb], b: &[Limb], mut c: Limb) -> Limb {
assert!(c <= 1);

for (a, &b) in a.iter_mut().zip(b) {
for (a, &b) in (a, b) {
let (r, overflow) = a.overflowing_sub(b);
let (r, overflow2) = r.overflowing_sub(c);
*a = r;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl TokenStream {
pub fn eq_unspanned(&self, other: &TokenStream) -> bool {
let mut t1 = self.trees();
let mut t2 = other.trees();
for (t1, t2) in t1.by_ref().zip(t2.by_ref()) {
for (t1, t2) in (&mut t1, &mut t2) {
if !t1.eq_unspanned(&t2) {
return false;
}
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
UseTreeKind::Glob => {}
UseTreeKind::Simple(_, id1, id2) => {
for (_, &id) in
self.expect_full_res_from_use(base_id).skip(1).zip([id1, id2].iter())
{
for (_, &id) in (self.expect_full_res_from_use(base_id).skip(1), &[id1, id2]) {
vec.push(id);
}
}
Expand Down Expand Up @@ -510,7 +508,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// won't be dealing with macros in the rest of the compiler.
// Essentially a single `use` which imports two names is desugared into
// two imports.
for (res, &new_node_id) in resolutions.zip([id1, id2].iter()) {
for (res, &new_node_id) in (resolutions, &[id1, id2]) {
let ident = *ident;
let mut path = path.clone();
for seg in &mut path.segments {
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ impl<'a> MethodDef<'a> {
// make a series of nested matches, to destructure the
// structs. This is actually right-to-left, but it shouldn't
// matter.
for (arg_expr, pat) in self_args.iter().zip(patterns) {
for (arg_expr, pat) in (self_args, patterns) {
body = cx.expr_match(
trait_.span,
arg_expr.clone(),
Expand Down Expand Up @@ -1364,7 +1364,7 @@ impl<'a> MethodDef<'a> {
let mut discriminant_test = cx.expr_bool(sp, true);

let mut first_ident = None;
for (&ident, self_arg) in vi_idents.iter().zip(&self_args) {
for (&ident, self_arg) in (&vi_idents, &self_args) {
let self_addr = cx.expr_addr_of(sp, self_arg.clone());
let variant_value =
deriving::call_intrinsic(cx, sp, sym::discriminant_value, vec![self_addr]);
Expand Down Expand Up @@ -1584,9 +1584,8 @@ impl<'a> TraitDef<'a> {
let subpats = self.create_subpatterns(cx, paths, mutbl, use_temporaries);
let pattern = match *struct_def {
VariantData::Struct(..) => {
let field_pats = subpats
let field_pats = (subpats, &ident_exprs)
.into_iter()
.zip(&ident_exprs)
.map(|(pat, &(sp, ident, ..))| {
if ident.is_none() {
cx.span_bug(sp, "a braced struct with unnamed fields in `derive`");
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,9 +914,8 @@ impl ThinLTOKeysMap {
modules: &[llvm::ThinLTOModule],
names: &[CString],
) -> Self {
let keys = modules
.iter()
.zip(names.iter())
let keys = (modules, names)
.into_iter()
.map(|(module, name)| {
let key = build_string(|rust_str| unsafe {
llvm::LLVMRustComputeLTOCacheKey(rust_str, module.identifier, data.0);
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,9 +1364,8 @@ impl Builder<'a, 'll, 'tcx> {
return Cow::Borrowed(args);
}

let casted_args: Vec<_> = param_tys
let casted_args: Vec<_> = (param_tys, args)
.into_iter()
.zip(args.iter())
.enumerate()
.map(|(i, (expected_ty, &actual_val))| {
let actual_ty = self.val_ty(actual_val);
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2331,9 +2331,8 @@ fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> Option<&'
if substs.types().next().is_some() {
let generics = cx.tcx.generics_of(def.did);
let names = get_parameter_names(cx, generics);
let template_params: Vec<_> = substs
.iter()
.zip(names)
let template_params: Vec<_> = (substs, names)
.into_iter()
.filter_map(|(kind, name)| {
if let GenericArgKind::Type(ty) = kind.unpack() {
let actual_type =
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,8 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
// Again, only create type information if full debuginfo is enabled
let template_params: Vec<_> = if cx.sess().opts.debuginfo == DebugInfo::Full {
let names = get_parameter_names(cx, generics);
substs
.iter()
.zip(names)
(substs, names)
.into_iter()
.filter_map(|(kind, name)| {
if let GenericArgKind::Type(ty) = kind.unpack() {
let actual_type =
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2157,9 +2157,8 @@ pub fn is_case_difference(sm: &SourceMap, suggested: &str, sp: Span) -> bool {
};
let ascii_confusables = &['c', 'f', 'i', 'k', 'o', 's', 'u', 'v', 'w', 'x', 'y', 'z'];
// All the chars that differ in capitalization are confusable (above):
let confusable = found
.chars()
.zip(suggested.chars())
let confusable = (found.chars(), suggested.chars())
.into_iter()
.filter(|(f, s)| f != s)
.all(|(f, s)| (ascii_confusables.contains(&f) || ascii_confusables.contains(&s)));
confusable && found.to_lowercase() == suggested.to_lowercase()
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_errors/src/styled_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ impl StyledBuffer {
// before we render, replace tabs with spaces
self.replace_tabs();

for (row, row_style) in self.text.iter().zip(&self.styles) {
for (row, row_style) in (&self.text, &self.styles) {
let mut current_style = Style::NoStyle;
let mut current_text = String::new();

for (&c, &s) in row.iter().zip(row_style) {
for (&c, &s) in (row, row_style) {
if s != current_style {
if !current_text.is_empty() {
styled_vec.push(StyledString { text: current_text, style: current_style });
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/mbe/macro_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,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 (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);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_index/src/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ where
{
assert_eq!(out_vec.len(), in_vec.len());
let mut changed = false;
for (out_elem, in_elem) in out_vec.iter_mut().zip(in_vec.iter()) {
for (out_elem, in_elem) in (out_vec, in_vec) {
let old_val = *out_elem;
let new_val = op(old_val, *in_elem);
*out_elem = new_val;
Expand Down Expand Up @@ -831,7 +831,7 @@ impl<R: Idx, C: Idx> BitMatrix<R, C> {
let (write_start, write_end) = self.range(write);
let words = &mut self.words[..];
let mut changed = false;
for (read_index, write_index) in (read_start..read_end).zip(write_start..write_end) {
for (read_index, write_index) in (read_start..read_end, write_start..write_end) {
let word = words[write_index];
let new_word = word | words[read_index];
words[write_index] = new_word;
Expand All @@ -847,7 +847,7 @@ impl<R: Idx, C: Idx> BitMatrix<R, C> {
assert_eq!(with.domain_size(), self.num_columns);
let (write_start, write_end) = self.range(write);
let mut changed = false;
for (read_index, write_index) in (0..with.words().len()).zip(write_start..write_end) {
for (read_index, write_index) in (0..with.words().len(), write_start..write_end) {
let word = self.words[write_index];
let new_word = word | with.words()[read_index];
self.words[write_index] = new_word;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {

// In terms of our example above, we are iterating over pairs like:
// [(?A, Vec<?0>), ('static, '?1), (?B, ?0)]
for (original_value, result_value) in original_values.var_values.iter().zip(result_values) {
for (original_value, result_value) in (&original_values.var_values, result_values) {
match result_value.unpack() {
GenericArgKind::Type(result_value) => {
// e.g., here `result_value` might be `?0` in the example above...
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
};
if has_default {
let types = substs.types().rev();
for ((def_id, has_default), actual) in type_params.zip(types) {
for ((def_id, has_default), actual) in (type_params, types) {
if !has_default {
break;
}
Expand Down Expand Up @@ -979,7 +979,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let len1 = sig1.inputs().len();
let len2 = sig2.inputs().len();
if len1 == len2 {
for (i, (l, r)) in sig1.inputs().iter().zip(sig2.inputs().iter()).enumerate() {
for (i, (l, r)) in (sig1.inputs(), sig2.inputs()).into_iter().enumerate() {
let (x1, x2) = self.cmp(l, r);
(values.0).0.extend(x1.0);
(values.1).0.extend(x2.0);
Expand Down Expand Up @@ -1236,9 +1236,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

const SEPARATOR: &str = "::";
let separator_len = SEPARATOR.len();
let split_idx: usize = t1_str
.split(SEPARATOR)
.zip(t2_str.split(SEPARATOR))
let split_idx: usize = (t1_str.split(SEPARATOR), t2_str.split(SEPARATOR))
.into_iter()
.take_while(|(mod1_str, mod2_str)| mod1_str == mod2_str)
.map(|(mod_str, _)| mod_str.len() + separator_len)
.sum();
Expand Down Expand Up @@ -1696,7 +1695,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
.find_map(|(path, msg)| (&path_str == path).then_some(msg))
{
let mut show_suggestion = true;
for (exp_ty, found_ty) in exp_substs.types().zip(found_substs.types()) {
for (exp_ty, found_ty) in (exp_substs.types(), found_substs.types()) {
match *exp_ty.kind() {
ty::Ref(_, exp_ty, _) => {
match (exp_ty.kind(), found_ty.kind()) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ impl<'tcx> LateContext<'tcx> {
pub fn match_def_path(&self, def_id: DefId, path: &[Symbol]) -> bool {
let names = self.get_def_path(def_id);

names.len() == path.len() && names.into_iter().zip(path.iter()).all(|(a, &b)| a == b)
names.len() == path.len() && (names, path).into_iter().all(|(a, &b)| a == b)
}

/// Gets the absolute path of `def_id` as a vector of `Symbol`.
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
let sig = self.cx.tcx.fn_sig(def_id);
let sig = self.cx.tcx.erase_late_bound_regions(&sig);

for (input_ty, input_hir) in sig.inputs().iter().zip(decl.inputs) {
for (input_ty, input_hir) in (sig.inputs(), decl.inputs) {
self.check_type_for_ffi_and_report_errors(input_hir.span, input_ty, false, false);
}

Expand Down Expand Up @@ -1321,10 +1321,8 @@ impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences {
layout
);

let (largest, slargest, largest_index) = enum_definition
.variants
.iter()
.zip(variants)
let (largest, slargest, largest_index) = (enum_definition.variants, variants)
.into_iter()
.map(|(variant, variant_layout)| {
// Subtract the size of the enum tag.
let bytes = variant_layout.size.bytes().saturating_sub(tag_size);
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_middle/src/infer/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,8 @@ impl<'tcx> CanonicalVarValues<'tcx> {
use crate::ty::subst::GenericArgKind;

CanonicalVarValues {
var_values: self
.var_values
.iter()
.zip(0..)
var_values: (&self.var_values, 0..)
.into_iter()
.map(|(kind, i)| match kind.unpack() {
GenericArgKind::Type(..) => {
tcx.mk_ty(ty::Bound(ty::INNERMOST, ty::BoundVar::from_u32(i).into())).into()
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2221,7 +2221,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
CtorKind::Fn => fmt_tuple(fmt, &name),
CtorKind::Fictive => {
let mut struct_fmt = fmt.debug_struct(&name);
for (field, place) in variant_def.fields.iter().zip(places) {
for (field, place) in (&variant_def.fields, places) {
struct_fmt.field(&field.ident.as_str(), place);
}
struct_fmt.finish()
Expand All @@ -2245,7 +2245,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
let mut struct_fmt = fmt.debug_struct(&name);

if let Some(upvars) = tcx.upvars_mentioned(def_id) {
for (&var_id, place) in upvars.keys().zip(places) {
for (&var_id, place) in (upvars.keys(), places) {
let var_name = tcx.hir().name(var_id);
struct_fmt.field(&var_name.as_str(), place);
}
Expand All @@ -2264,7 +2264,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
let mut struct_fmt = fmt.debug_struct(&name);

if let Some(upvars) = tcx.upvars_mentioned(def_id) {
for (&var_id, place) in upvars.keys().zip(places) {
for (&var_id, place) in (upvars.keys(), places) {
let var_name = tcx.hir().name(var_id);
struct_fmt.field(&var_name.as_str(), place);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl SwitchTargets {
///
/// Note that this may yield 0 elements. Only the `otherwise` branch is mandatory.
pub fn iter(&self) -> SwitchTargetsIter<'_> {
SwitchTargetsIter { inner: self.values.iter().zip(self.targets.iter()) }
SwitchTargetsIter { inner: (&self.values, &self.targets).into_iter() }
}

/// Returns a slice with all possible jump targets (including the fallback target).
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
} else {
// Try to use a ScalarPair for all tagged enums.
let mut common_prim = None;
for (field_layouts, layout_variant) in variants.iter().zip(&layout_variants) {
for (field_layouts, layout_variant) in (&variants, &layout_variants) {
let offsets = match layout_variant.fields {
FieldsShape::Arbitrary { ref offsets, .. } => offsets,
_ => bug!(),
Expand Down Expand Up @@ -1509,7 +1509,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
const INVALID_FIELD_IDX: u32 = !0;
let mut combined_inverse_memory_index =
vec![INVALID_FIELD_IDX; promoted_memory_index.len() + memory_index.len()];
let mut offsets_and_memory_index = offsets.into_iter().zip(memory_index);
let mut offsets_and_memory_index = (offsets, memory_index).into_iter();
let combined_offsets = variant_fields
.iter()
.enumerate()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ pub trait PrettyPrinter<'tcx>:
CtorKind::Fictive => {
p!(" {{ ");
let mut first = true;
for (field_def, field) in variant_def.fields.iter().zip(fields) {
for (field_def, field) in (&variant_def.fields, fields) {
if !first {
p!(", ");
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
// Both the variant and each field have to be equal.
if a_destructured.variant == b_destructured.variant {
for (a_field, b_field) in
a_destructured.fields.iter().zip(b_destructured.fields.iter())
(a_destructured.fields, b_destructured.fields)
{
relation.consts(a_field, b_field)?;
}
Expand Down Expand Up @@ -624,7 +624,7 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {
return Err(TypeError::ExistentialMismatch(expected_found(relation, a, b)));
}

let v = a_v.into_iter().zip(b_v.into_iter()).map(|(ep_a, ep_b)| {
let v = (a_v, b_v).into_iter().map(|(ep_a, ep_b)| {
use crate::ty::ExistentialPredicate::*;
match (ep_a, ep_b) {
(Trait(a), Trait(b)) => Ok(Trait(relation.relate(a, b)?)),
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,8 @@ impl<'tcx> TyCtxt<'tcx> {
_ => bug!(),
};

let result = item_substs
.iter()
.zip(impl_substs.iter())
let result = (item_substs, impl_substs)
.into_iter()
.filter(|&(_, k)| {
match k.unpack() {
GenericArgKind::Lifetime(&ty::RegionKind::ReEarlyBound(ref ebr)) => {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let expr = &self.infcx.tcx.hir().expect_expr(hir_id).kind;
debug!("closure_span: hir_id={:?} expr={:?}", hir_id, expr);
if let hir::ExprKind::Closure(.., body_id, args_span, _) = expr {
for ((upvar_hir_id, upvar), place) in
self.infcx.tcx.upvars_mentioned(def_id)?.iter().zip(places)
for ((upvar_hir_id, upvar), place) in (self.infcx.tcx.upvars_mentioned(def_id)?, places)
{
match place {
Operand::Copy(place) | Operand::Move(place)
Expand Down
Loading