Use zip_eq to enforce that things being zipped have equal sizes · rust-lang/rust@c811662 (original) (raw)

11 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -3868,6 +3868,7 @@ dependencies = [
3868 3868 name = "rustc_hir_analysis"
3869 3869 version = "0.0.0"
3870 3870 dependencies = [
3871 +"itertools",
3871 3872 "rustc_arena",
3872 3873 "rustc_ast",
3873 3874 "rustc_attr",
@@ -3906,6 +3907,7 @@ dependencies = [
3906 3907 name = "rustc_hir_typeck"
3907 3908 version = "0.0.0"
3908 3909 dependencies = [
3910 +"itertools",
3909 3911 "rustc_ast",
3910 3912 "rustc_attr",
3911 3913 "rustc_data_structures",
@@ -4189,6 +4191,7 @@ name = "rustc_mir_build"
4189 4191 version = "0.0.0"
4190 4192 dependencies = [
4191 4193 "either",
4194 +"itertools",
4192 4195 "rustc_apfloat",
4193 4196 "rustc_arena",
4194 4197 "rustc_ast",
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
7 7 //! `RETURN_PLACE` the MIR arguments) are always fully normalized (and
8 8 //! contain revealed `impl Trait` values).
9 9
10 +use itertools::Itertools;
10 11 use rustc_infer::infer::BoundRegionConversionTime;
11 12 use rustc_middle::mir::*;
12 13 use rustc_middle::ty::{self, Ty};
@@ -39,9 +40,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
39 40 user_provided_sig,
40 41 );
41 42
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
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
45 52 ) {
46 53 self.ascribe_user_type_skip_wf(
47 54 arg_decl.ty,
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ doctest = false
9 9
10 10 [dependencies]
11 11 # tidy-alphabetical-start
12 +itertools = "0.11"
12 13 rustc_arena = { path = "../rustc_arena" }
13 14 rustc_ast = { path = "../rustc_ast" }
14 15 rustc_attr = { path = "../rustc_attr" }
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
3 3 //!
4 4 //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/variance.html
5 5
6 +use itertools::Itertools;
6 7 use rustc_arena::DroplessArena;
7 8 use rustc_hir::def::DefKind;
8 9 use rustc_hir::def_id::{DefId, LocalDefId};
@@ -91,7 +92,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
91 92 fn visit_opaque(&mut self, def_id: DefId, args: GenericArgsRef<'tcx>) -> ControlFlow<!> {
92 93 if def_id != self.root_def_id && self.tcx.is_descendant_of(def_id, self.root_def_id) {
93 94 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) {
95 96 if *v != ty::Bivariant {
96 97 a.visit_with(self)?;
97 98 }
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ edition = "2021"
5 5
6 6 [dependencies]
7 7 # tidy-alphabetical-start
8 +itertools = "0.11"
8 9 rustc_ast = { path = "../rustc_ast" }
9 10 rustc_attr = { path = "../rustc_attr" }
10 11 rustc_data_structures = { path = "../rustc_data_structures" }
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
2 2 use super::method::MethodCallee;
3 3 use super::{FnCtxt, PlaceOp};
4 4
5 +use itertools::Itertools;
5 6 use rustc_hir_analysis::autoderef::{Autoderef, AutoderefKind};
6 7 use rustc_infer::infer::InferOk;
7 8 use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref};
@@ -32,8 +33,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32 33 &self,
33 34 autoderef: &Autoderef<'a, 'tcx>,
34 35 ) -> InferOk<'tcx, Vec<Adjustment<'tcx>>> {
35 -let mut obligations = vec![];
36 36 let steps = autoderef.steps();
37 +if steps.is_empty() {
38 +return InferOk { obligations: vec![], value: vec![] };
39 +}
40 +
41 +let mut obligations = vec![];
37 42 let targets =
38 43 steps.iter().skip(1).map(|&(ty, _)
39 44 let steps: Vec<_> = steps
@@ -54,7 +59,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
54 59 None
55 60 }
56 61 })
57 -.zip(targets)
62 +.zip_eq(targets)
58 63 .map(|(autoderef, target)
59 64 .collect();
60 65
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ use crate::{errors, Expectation::*};
8 8 use crate::{
9 9 struct_span_err, BreakableCtxt, Diverges, Expectation, FnCtxt, Needs, RawTy, TupleArgumentsFlag,
10 10 };
11 +use itertools::Itertools;
11 12 use rustc_ast as ast;
12 13 use rustc_data_structures::fx::FxIndexSet;
13 14 use rustc_errors::{
@@ -420,7 +421,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
420 421 formal_input_tys
421 422 .iter()
422 423 .copied()
423 -.zip(expected_input_tys.iter().copied())
424 +.zip_eq(expected_input_tys.iter().copied())
424 425 .map(|vars
425 426 );
426 427
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ edition = "2021"
6 6 [dependencies]
7 7 # tidy-alphabetical-start
8 8 either = "1"
9 +itertools = "0.11"
9 10 rustc_apfloat = "0.2.0"
10 11 rustc_arena = { path = "../rustc_arena" }
11 12 rustc_ast = { path = "../rustc_ast" }
Original file line number Diff line number Diff line change
@@ -836,7 +836,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
836 836 self.upvars = tcx
837 837 .closure_captures(self.def_id)
838 838 .iter()
839 -.zip(capture_tys)
839 +.zip_eq(capture_tys)
840 840 .enumerate()
841 841 .map(|(i, (captured_place, ty))
842 842 let name = captured_place.to_symbol();
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ use crate::errors;
2 2 use crate::thir::cx::region::Scope;
3 3 use crate::thir::cx::Cx;
4 4 use crate::thir::util::UserAnnotatedTyHelpers;
5 +use itertools::Itertools;
5 6 use rustc_data_structures::stack::ensure_sufficient_stack;
6 7 use rustc_hir as hir;
7 8 use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
@@ -565,7 +566,7 @@ impl<'tcx> Cx<'tcx> {
565 566 .tcx
566 567 .closure_captures(def_id)
567 568 .iter()
568 -.zip(args.upvar_tys())
569 +.zip_eq(args.upvar_tys())
569 570 .map(|(captured_place, ty)
570 571 let upvars = self.capture_upvar(expr, captured_place, ty);
571 572 self.thir.exprs.push(upvars)
Original file line number Diff line number Diff line change
@@ -1057,6 +1057,8 @@ fn variant_info_for_coroutine<'tcx>(
1057 1057 def_id: DefId,
1058 1058 args: ty::GenericArgsRef<'tcx>,
1059 1059 ) -> (Vec<VariantInfo>, Option<Size>) {
1060 +use itertools::Itertools;
1061 +
1060 1062 let Variants::Multiple { tag, ref tag_encoding, tag_field, .. } = layout.variants else {
1061 1063 return (vec![], None);
1062 1064 };
@@ -1069,7 +1071,7 @@ fn variant_info_for_coroutine<'tcx>(
1069 1071 .as_coroutine()
1070 1072 .upvar_tys()
1071 1073 .iter()
1072 -.zip(upvar_names)
1074 +.zip_eq(upvar_names)
1073 1075 .enumerate()
1074 1076 .map(|(field_idx, (_, name))
1075 1077 let field_layout = layout.field(cx, field_idx);