Skip to content

Commit c811662

Browse files
Use zip_eq to enforce that things being zipped have equal sizes
1 parent c5cb87c commit c811662

File tree

11 files changed

+33
-10
lines changed

11 files changed

+33
-10
lines changed

Cargo.lock

+3
Original file line numberDiff line numberDiff line change
@@ -3868,6 +3868,7 @@ dependencies = [
38683868
name = "rustc_hir_analysis"
38693869
version = "0.0.0"
38703870
dependencies = [
3871+
"itertools",
38713872
"rustc_arena",
38723873
"rustc_ast",
38733874
"rustc_attr",
@@ -3906,6 +3907,7 @@ dependencies = [
39063907
name = "rustc_hir_typeck"
39073908
version = "0.0.0"
39083909
dependencies = [
3910+
"itertools",
39093911
"rustc_ast",
39103912
"rustc_attr",
39113913
"rustc_data_structures",
@@ -4189,6 +4191,7 @@ name = "rustc_mir_build"
41894191
version = "0.0.0"
41904192
dependencies = [
41914193
"either",
4194+
"itertools",
41924195
"rustc_apfloat",
41934196
"rustc_arena",
41944197
"rustc_ast",

compiler/rustc_borrowck/src/type_check/input_output.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! `RETURN_PLACE` the MIR arguments) are always fully normalized (and
88
//! contain revealed `impl Trait` values).
99
10+
use itertools::Itertools;
1011
use rustc_infer::infer::BoundRegionConversionTime;
1112
use rustc_middle::mir::*;
1213
use rustc_middle::ty::{self, Ty};
@@ -39,9 +40,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
3940
user_provided_sig,
4041
);
4142

42-
for (&user_ty, arg_decl) in user_provided_sig.inputs().iter().zip(
43-
// In MIR, closure args begin with an implicit `self`. Skip it!
44-
body.args_iter().skip(1).map(|local| &body.local_decls[local]),
43+
let is_coroutine_with_implicit_resume_ty = self.tcx().is_coroutine(mir_def_id.to_def_id())
44+
&& user_provided_sig.inputs().is_empty();
45+
46+
for (&user_ty, arg_decl) in user_provided_sig.inputs().iter().zip_eq(
47+
// In MIR, closure args begin with an implicit `self`.
48+
// Also, coroutines have a resume type which may be implicitly `()`.
49+
body.args_iter()
50+
.skip(1 + if is_coroutine_with_implicit_resume_ty { 1 } else { 0 })
51+
.map(|local| &body.local_decls[local]),
4552
) {
4653
self.ascribe_user_type_skip_wf(
4754
arg_decl.ty,

compiler/rustc_hir_analysis/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ doctest = false
99

1010
[dependencies]
1111
# tidy-alphabetical-start
12+
itertools = "0.11"
1213
rustc_arena = { path = "../rustc_arena" }
1314
rustc_ast = { path = "../rustc_ast" }
1415
rustc_attr = { path = "../rustc_attr" }

compiler/rustc_hir_analysis/src/variance/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//!
44
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/variance.html
55
6+
use itertools::Itertools;
67
use rustc_arena::DroplessArena;
78
use rustc_hir::def::DefKind;
89
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -91,7 +92,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
9192
fn visit_opaque(&mut self, def_id: DefId, args: GenericArgsRef<'tcx>) -> ControlFlow<!> {
9293
if def_id != self.root_def_id && self.tcx.is_descendant_of(def_id, self.root_def_id) {
9394
let child_variances = self.tcx.variances_of(def_id);
94-
for (a, v) in args.iter().zip(child_variances) {
95+
for (a, v) in args.iter().zip_eq(child_variances) {
9596
if *v != ty::Bivariant {
9697
a.visit_with(self)?;
9798
}

compiler/rustc_hir_typeck/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
itertools = "0.11"
89
rustc_ast = { path = "../rustc_ast" }
910
rustc_attr = { path = "../rustc_attr" }
1011
rustc_data_structures = { path = "../rustc_data_structures" }

compiler/rustc_hir_typeck/src/autoderef.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use super::method::MethodCallee;
33
use super::{FnCtxt, PlaceOp};
44

5+
use itertools::Itertools;
56
use rustc_hir_analysis::autoderef::{Autoderef, AutoderefKind};
67
use rustc_infer::infer::InferOk;
78
use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref};
@@ -32,8 +33,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3233
&self,
3334
autoderef: &Autoderef<'a, 'tcx>,
3435
) -> InferOk<'tcx, Vec<Adjustment<'tcx>>> {
35-
let mut obligations = vec![];
3636
let steps = autoderef.steps();
37+
if steps.is_empty() {
38+
return InferOk { obligations: vec![], value: vec![] };
39+
}
40+
41+
let mut obligations = vec![];
3742
let targets =
3843
steps.iter().skip(1).map(|&(ty, _)| ty).chain(iter::once(autoderef.final_ty(false)));
3944
let steps: Vec<_> = steps
@@ -54,7 +59,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5459
None
5560
}
5661
})
57-
.zip(targets)
62+
.zip_eq(targets)
5863
.map(|(autoderef, target)| Adjustment { kind: Adjust::Deref(autoderef), target })
5964
.collect();
6065

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{errors, Expectation::*};
88
use crate::{
99
struct_span_err, BreakableCtxt, Diverges, Expectation, FnCtxt, Needs, RawTy, TupleArgumentsFlag,
1010
};
11+
use itertools::Itertools;
1112
use rustc_ast as ast;
1213
use rustc_data_structures::fx::FxIndexSet;
1314
use rustc_errors::{
@@ -420,7 +421,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
420421
formal_input_tys
421422
.iter()
422423
.copied()
423-
.zip(expected_input_tys.iter().copied())
424+
.zip_eq(expected_input_tys.iter().copied())
424425
.map(|vars| self.resolve_vars_if_possible(vars)),
425426
);
426427

compiler/rustc_mir_build/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66
[dependencies]
77
# tidy-alphabetical-start
88
either = "1"
9+
itertools = "0.11"
910
rustc_apfloat = "0.2.0"
1011
rustc_arena = { path = "../rustc_arena" }
1112
rustc_ast = { path = "../rustc_ast" }

compiler/rustc_mir_build/src/build/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
836836
self.upvars = tcx
837837
.closure_captures(self.def_id)
838838
.iter()
839-
.zip(capture_tys)
839+
.zip_eq(capture_tys)
840840
.enumerate()
841841
.map(|(i, (captured_place, ty))| {
842842
let name = captured_place.to_symbol();

compiler/rustc_mir_build/src/thir/cx/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::errors;
22
use crate::thir::cx::region::Scope;
33
use crate::thir::cx::Cx;
44
use crate::thir::util::UserAnnotatedTyHelpers;
5+
use itertools::Itertools;
56
use rustc_data_structures::stack::ensure_sufficient_stack;
67
use rustc_hir as hir;
78
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
@@ -565,7 +566,7 @@ impl<'tcx> Cx<'tcx> {
565566
.tcx
566567
.closure_captures(def_id)
567568
.iter()
568-
.zip(args.upvar_tys())
569+
.zip_eq(args.upvar_tys())
569570
.map(|(captured_place, ty)| {
570571
let upvars = self.capture_upvar(expr, captured_place, ty);
571572
self.thir.exprs.push(upvars)

compiler/rustc_ty_utils/src/layout.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,8 @@ fn variant_info_for_coroutine<'tcx>(
10571057
def_id: DefId,
10581058
args: ty::GenericArgsRef<'tcx>,
10591059
) -> (Vec<VariantInfo>, Option<Size>) {
1060+
use itertools::Itertools;
1061+
10601062
let Variants::Multiple { tag, ref tag_encoding, tag_field, .. } = layout.variants else {
10611063
return (vec![], None);
10621064
};
@@ -1069,7 +1071,7 @@ fn variant_info_for_coroutine<'tcx>(
10691071
.as_coroutine()
10701072
.upvar_tys()
10711073
.iter()
1072-
.zip(upvar_names)
1074+
.zip_eq(upvar_names)
10731075
.enumerate()
10741076
.map(|(field_idx, (_, name))| {
10751077
let field_layout = layout.field(cx, field_idx);

0 commit comments

Comments
 (0)