Skip to content

Commit 71569a0

Browse files
authored
Unrolled build for rust-lang#119971
Rollup merge of rust-lang#119971 - compiler-errors:zip-eq, r=nnethercote Use `zip_eq` to enforce that things being zipped have equal sizes Some `zip`s are best enforced to be equal, since size mismatches suggest deeper bugs in the compiler.
2 parents 1ead476 + c811662 commit 71569a0

File tree

11 files changed

+35
-11
lines changed

11 files changed

+35
-11
lines changed

Cargo.lock

+3
Original file line numberDiff line numberDiff line change
@@ -3879,6 +3879,7 @@ dependencies = [
38793879
name = "rustc_hir_analysis"
38803880
version = "0.0.0"
38813881
dependencies = [
3882+
"itertools",
38823883
"rustc_arena",
38833884
"rustc_ast",
38843885
"rustc_attr",
@@ -3917,6 +3918,7 @@ dependencies = [
39173918
name = "rustc_hir_typeck"
39183919
version = "0.0.0"
39193920
dependencies = [
3921+
"itertools",
39203922
"rustc_ast",
39213923
"rustc_attr",
39223924
"rustc_data_structures",
@@ -4200,6 +4202,7 @@ name = "rustc_mir_build"
42004202
version = "0.0.0"
42014203
dependencies = [
42024204
"either",
4205+
"itertools",
42034206
"rustc_apfloat",
42044207
"rustc_arena",
42054208
"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
@@ -9,6 +9,7 @@ use crate::{
99
struct_span_code_err, BreakableCtxt, Diverges, Expectation, FnCtxt, Needs, RawTy,
1010
TupleArgumentsFlag,
1111
};
12+
use itertools::Itertools;
1213
use rustc_ast as ast;
1314
use rustc_data_structures::fx::FxIndexSet;
1415
use rustc_errors::{
@@ -421,7 +422,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
421422
formal_input_tys
422423
.iter()
423424
.copied()
424-
.zip(expected_input_tys.iter().copied())
425+
.zip_eq(expected_input_tys.iter().copied())
425426
.map(|vars| self.resolve_vars_if_possible(vars)),
426427
);
427428

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::build::expr::as_place::PlaceBuilder;
22
use crate::build::scope::DropKind;
3+
use itertools::Itertools;
34
use rustc_apfloat::ieee::{Double, Single};
45
use rustc_apfloat::Float;
56
use rustc_ast::attr;
@@ -654,7 +655,7 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
654655
ty::ClosureKind::FnOnce => closure_ty,
655656
};
656657
(
657-
[self_ty].into_iter().chain(sig.inputs().to_vec()).collect(),
658+
[self_ty].into_iter().chain(sig.inputs()[0].tuple_fields()).collect(),
658659
sig.output(),
659660
None,
660661
)
@@ -835,7 +836,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
835836
self.upvars = tcx
836837
.closure_captures(self.def_id)
837838
.iter()
838-
.zip(capture_tys)
839+
.zip_eq(capture_tys)
839840
.enumerate()
840841
.map(|(i, (captured_place, ty))| {
841842
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
@@ -1052,6 +1052,8 @@ fn variant_info_for_coroutine<'tcx>(
10521052
def_id: DefId,
10531053
args: ty::GenericArgsRef<'tcx>,
10541054
) -> (Vec<VariantInfo>, Option<Size>) {
1055+
use itertools::Itertools;
1056+
10551057
let Variants::Multiple { tag, ref tag_encoding, tag_field, .. } = layout.variants else {
10561058
return (vec![], None);
10571059
};
@@ -1064,7 +1066,7 @@ fn variant_info_for_coroutine<'tcx>(
10641066
.as_coroutine()
10651067
.upvar_tys()
10661068
.iter()
1067-
.zip(upvar_names)
1069+
.zip_eq(upvar_names)
10681070
.enumerate()
10691071
.map(|(field_idx, (_, name))| {
10701072
let field_layout = layout.field(cx, field_idx);

0 commit comments

Comments
 (0)