Use zip_eq to enforce that things being zipped have equal sizes
This commit is contained in:
parent
c5cb87cf0c
commit
c811662fb0
11 changed files with 33 additions and 10 deletions
|
@ -3868,6 +3868,7 @@ dependencies = [
|
||||||
name = "rustc_hir_analysis"
|
name = "rustc_hir_analysis"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"itertools",
|
||||||
"rustc_arena",
|
"rustc_arena",
|
||||||
"rustc_ast",
|
"rustc_ast",
|
||||||
"rustc_attr",
|
"rustc_attr",
|
||||||
|
@ -3906,6 +3907,7 @@ dependencies = [
|
||||||
name = "rustc_hir_typeck"
|
name = "rustc_hir_typeck"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"itertools",
|
||||||
"rustc_ast",
|
"rustc_ast",
|
||||||
"rustc_attr",
|
"rustc_attr",
|
||||||
"rustc_data_structures",
|
"rustc_data_structures",
|
||||||
|
@ -4189,6 +4191,7 @@ name = "rustc_mir_build"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"either",
|
"either",
|
||||||
|
"itertools",
|
||||||
"rustc_apfloat",
|
"rustc_apfloat",
|
||||||
"rustc_arena",
|
"rustc_arena",
|
||||||
"rustc_ast",
|
"rustc_ast",
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
//! `RETURN_PLACE` the MIR arguments) are always fully normalized (and
|
//! `RETURN_PLACE` the MIR arguments) are always fully normalized (and
|
||||||
//! contain revealed `impl Trait` values).
|
//! contain revealed `impl Trait` values).
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
use rustc_infer::infer::BoundRegionConversionTime;
|
use rustc_infer::infer::BoundRegionConversionTime;
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::{self, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
|
@ -39,9 +40,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
user_provided_sig,
|
user_provided_sig,
|
||||||
);
|
);
|
||||||
|
|
||||||
for (&user_ty, arg_decl) in user_provided_sig.inputs().iter().zip(
|
let is_coroutine_with_implicit_resume_ty = self.tcx().is_coroutine(mir_def_id.to_def_id())
|
||||||
// In MIR, closure args begin with an implicit `self`. Skip it!
|
&& user_provided_sig.inputs().is_empty();
|
||||||
body.args_iter().skip(1).map(|local| &body.local_decls[local]),
|
|
||||||
|
for (&user_ty, arg_decl) in user_provided_sig.inputs().iter().zip_eq(
|
||||||
|
// In MIR, closure args begin with an implicit `self`.
|
||||||
|
// Also, coroutines have a resume type which may be implicitly `()`.
|
||||||
|
body.args_iter()
|
||||||
|
.skip(1 + if is_coroutine_with_implicit_resume_ty { 1 } else { 0 })
|
||||||
|
.map(|local| &body.local_decls[local]),
|
||||||
) {
|
) {
|
||||||
self.ascribe_user_type_skip_wf(
|
self.ascribe_user_type_skip_wf(
|
||||||
arg_decl.ty,
|
arg_decl.ty,
|
||||||
|
|
|
@ -9,6 +9,7 @@ doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# tidy-alphabetical-start
|
# tidy-alphabetical-start
|
||||||
|
itertools = "0.11"
|
||||||
rustc_arena = { path = "../rustc_arena" }
|
rustc_arena = { path = "../rustc_arena" }
|
||||||
rustc_ast = { path = "../rustc_ast" }
|
rustc_ast = { path = "../rustc_ast" }
|
||||||
rustc_attr = { path = "../rustc_attr" }
|
rustc_attr = { path = "../rustc_attr" }
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
//!
|
//!
|
||||||
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/variance.html
|
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/variance.html
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
use rustc_arena::DroplessArena;
|
use rustc_arena::DroplessArena;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
|
@ -91,7 +92,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
|
||||||
fn visit_opaque(&mut self, def_id: DefId, args: GenericArgsRef<'tcx>) -> ControlFlow<!> {
|
fn visit_opaque(&mut self, def_id: DefId, args: GenericArgsRef<'tcx>) -> ControlFlow<!> {
|
||||||
if def_id != self.root_def_id && self.tcx.is_descendant_of(def_id, self.root_def_id) {
|
if def_id != self.root_def_id && self.tcx.is_descendant_of(def_id, self.root_def_id) {
|
||||||
let child_variances = self.tcx.variances_of(def_id);
|
let child_variances = self.tcx.variances_of(def_id);
|
||||||
for (a, v) in args.iter().zip(child_variances) {
|
for (a, v) in args.iter().zip_eq(child_variances) {
|
||||||
if *v != ty::Bivariant {
|
if *v != ty::Bivariant {
|
||||||
a.visit_with(self)?;
|
a.visit_with(self)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# tidy-alphabetical-start
|
# tidy-alphabetical-start
|
||||||
|
itertools = "0.11"
|
||||||
rustc_ast = { path = "../rustc_ast" }
|
rustc_ast = { path = "../rustc_ast" }
|
||||||
rustc_attr = { path = "../rustc_attr" }
|
rustc_attr = { path = "../rustc_attr" }
|
||||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
use super::method::MethodCallee;
|
use super::method::MethodCallee;
|
||||||
use super::{FnCtxt, PlaceOp};
|
use super::{FnCtxt, PlaceOp};
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
use rustc_hir_analysis::autoderef::{Autoderef, AutoderefKind};
|
use rustc_hir_analysis::autoderef::{Autoderef, AutoderefKind};
|
||||||
use rustc_infer::infer::InferOk;
|
use rustc_infer::infer::InferOk;
|
||||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref};
|
use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref};
|
||||||
|
@ -32,8 +33,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
autoderef: &Autoderef<'a, 'tcx>,
|
autoderef: &Autoderef<'a, 'tcx>,
|
||||||
) -> InferOk<'tcx, Vec<Adjustment<'tcx>>> {
|
) -> InferOk<'tcx, Vec<Adjustment<'tcx>>> {
|
||||||
let mut obligations = vec![];
|
|
||||||
let steps = autoderef.steps();
|
let steps = autoderef.steps();
|
||||||
|
if steps.is_empty() {
|
||||||
|
return InferOk { obligations: vec![], value: vec![] };
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut obligations = vec![];
|
||||||
let targets =
|
let targets =
|
||||||
steps.iter().skip(1).map(|&(ty, _)| ty).chain(iter::once(autoderef.final_ty(false)));
|
steps.iter().skip(1).map(|&(ty, _)| ty).chain(iter::once(autoderef.final_ty(false)));
|
||||||
let steps: Vec<_> = steps
|
let steps: Vec<_> = steps
|
||||||
|
@ -54,7 +59,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.zip(targets)
|
.zip_eq(targets)
|
||||||
.map(|(autoderef, target)| Adjustment { kind: Adjust::Deref(autoderef), target })
|
.map(|(autoderef, target)| Adjustment { kind: Adjust::Deref(autoderef), target })
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ use crate::{errors, Expectation::*};
|
||||||
use crate::{
|
use crate::{
|
||||||
struct_span_err, BreakableCtxt, Diverges, Expectation, FnCtxt, Needs, RawTy, TupleArgumentsFlag,
|
struct_span_err, BreakableCtxt, Diverges, Expectation, FnCtxt, Needs, RawTy, TupleArgumentsFlag,
|
||||||
};
|
};
|
||||||
|
use itertools::Itertools;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_data_structures::fx::FxIndexSet;
|
use rustc_data_structures::fx::FxIndexSet;
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
|
@ -420,7 +421,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
formal_input_tys
|
formal_input_tys
|
||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
.zip(expected_input_tys.iter().copied())
|
.zip_eq(expected_input_tys.iter().copied())
|
||||||
.map(|vars| self.resolve_vars_if_possible(vars)),
|
.map(|vars| self.resolve_vars_if_possible(vars)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# tidy-alphabetical-start
|
# tidy-alphabetical-start
|
||||||
either = "1"
|
either = "1"
|
||||||
|
itertools = "0.11"
|
||||||
rustc_apfloat = "0.2.0"
|
rustc_apfloat = "0.2.0"
|
||||||
rustc_arena = { path = "../rustc_arena" }
|
rustc_arena = { path = "../rustc_arena" }
|
||||||
rustc_ast = { path = "../rustc_ast" }
|
rustc_ast = { path = "../rustc_ast" }
|
||||||
|
|
|
@ -836,7 +836,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
self.upvars = tcx
|
self.upvars = tcx
|
||||||
.closure_captures(self.def_id)
|
.closure_captures(self.def_id)
|
||||||
.iter()
|
.iter()
|
||||||
.zip(capture_tys)
|
.zip_eq(capture_tys)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, (captured_place, ty))| {
|
.map(|(i, (captured_place, ty))| {
|
||||||
let name = captured_place.to_symbol();
|
let name = captured_place.to_symbol();
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::errors;
|
||||||
use crate::thir::cx::region::Scope;
|
use crate::thir::cx::region::Scope;
|
||||||
use crate::thir::cx::Cx;
|
use crate::thir::cx::Cx;
|
||||||
use crate::thir::util::UserAnnotatedTyHelpers;
|
use crate::thir::util::UserAnnotatedTyHelpers;
|
||||||
|
use itertools::Itertools;
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
|
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
|
||||||
|
@ -565,7 +566,7 @@ impl<'tcx> Cx<'tcx> {
|
||||||
.tcx
|
.tcx
|
||||||
.closure_captures(def_id)
|
.closure_captures(def_id)
|
||||||
.iter()
|
.iter()
|
||||||
.zip(args.upvar_tys())
|
.zip_eq(args.upvar_tys())
|
||||||
.map(|(captured_place, ty)| {
|
.map(|(captured_place, ty)| {
|
||||||
let upvars = self.capture_upvar(expr, captured_place, ty);
|
let upvars = self.capture_upvar(expr, captured_place, ty);
|
||||||
self.thir.exprs.push(upvars)
|
self.thir.exprs.push(upvars)
|
||||||
|
|
|
@ -1057,6 +1057,8 @@ fn variant_info_for_coroutine<'tcx>(
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
args: ty::GenericArgsRef<'tcx>,
|
args: ty::GenericArgsRef<'tcx>,
|
||||||
) -> (Vec<VariantInfo>, Option<Size>) {
|
) -> (Vec<VariantInfo>, Option<Size>) {
|
||||||
|
use itertools::Itertools;
|
||||||
|
|
||||||
let Variants::Multiple { tag, ref tag_encoding, tag_field, .. } = layout.variants else {
|
let Variants::Multiple { tag, ref tag_encoding, tag_field, .. } = layout.variants else {
|
||||||
return (vec![], None);
|
return (vec![], None);
|
||||||
};
|
};
|
||||||
|
@ -1069,7 +1071,7 @@ fn variant_info_for_coroutine<'tcx>(
|
||||||
.as_coroutine()
|
.as_coroutine()
|
||||||
.upvar_tys()
|
.upvar_tys()
|
||||||
.iter()
|
.iter()
|
||||||
.zip(upvar_names)
|
.zip_eq(upvar_names)
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(field_idx, (_, name))| {
|
.map(|(field_idx, (_, name))| {
|
||||||
let field_layout = layout.field(cx, field_idx);
|
let field_layout = layout.field(cx, field_idx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue