Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/infer/closure.rs')
-rw-r--r--crates/hir-ty/src/infer/closure.rs54
1 files changed, 28 insertions, 26 deletions
diff --git a/crates/hir-ty/src/infer/closure.rs b/crates/hir-ty/src/infer/closure.rs
index 14b0c9076c..19ffa3a939 100644
--- a/crates/hir-ty/src/infer/closure.rs
+++ b/crates/hir-ty/src/infer/closure.rs
@@ -13,7 +13,7 @@ use rustc_type_ir::{
ClosureArgs, ClosureArgsParts, CoroutineArgs, CoroutineArgsParts, CoroutineClosureArgs,
CoroutineClosureArgsParts, Interner, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
TypeVisitor,
- inherent::{BoundExistentialPredicates, GenericArgs as _, IntoKind, SliceLike, Ty as _},
+ inherent::{BoundExistentialPredicates, GenericArgs as _, IntoKind, Ty as _},
};
use tracing::debug;
@@ -22,9 +22,8 @@ use crate::{
db::{InternedClosure, InternedCoroutine},
infer::{BreakableKind, Diverges, coerce::CoerceMany},
next_solver::{
- AliasTy, Binder, BoundRegionKind, BoundVarKind, BoundVarKinds, ClauseKind, DbInterner,
- ErrorGuaranteed, FnSig, GenericArgs, PolyFnSig, PolyProjectionPredicate, Predicate,
- PredicateKind, SolverDefId, Ty, TyKind,
+ AliasTy, Binder, ClauseKind, DbInterner, ErrorGuaranteed, FnSig, GenericArgs, PolyFnSig,
+ PolyProjectionPredicate, Predicate, PredicateKind, SolverDefId, Ty, TyKind,
abi::Safety,
infer::{
BoundRegionConversionTime, InferOk, InferResult,
@@ -73,16 +72,17 @@ impl<'db> InferenceContext<'_, 'db> {
let parent_args = GenericArgs::identity_for_item(interner, self.generic_def.into());
// FIXME: Make this an infer var and infer it later.
- let tupled_upvars_ty = self.types.unit;
+ let tupled_upvars_ty = self.types.types.unit;
let (id, ty, resume_yield_tys) = match closure_kind {
ClosureKind::Coroutine(_) => {
let yield_ty = self.table.next_ty_var();
- let resume_ty = liberated_sig.inputs().get(0).unwrap_or(self.types.unit);
+ let resume_ty =
+ liberated_sig.inputs().first().copied().unwrap_or(self.types.types.unit);
// FIXME: Infer the upvars later.
let parts = CoroutineArgsParts {
- parent_args,
- kind_ty: self.types.unit,
+ parent_args: parent_args.as_slice(),
+ kind_ty: self.types.types.unit,
resume_ty,
yield_ty,
return_ty: body_ret_ty,
@@ -119,7 +119,7 @@ impl<'db> InferenceContext<'_, 'db> {
};
// FIXME: Infer the kind later if needed.
let parts = ClosureArgsParts {
- parent_args,
+ parent_args: parent_args.as_slice(),
closure_kind_ty: Ty::from_closure_kind(
interner,
expected_kind.unwrap_or(rustc_type_ir::ClosureKind::Fn),
@@ -140,9 +140,9 @@ impl<'db> InferenceContext<'_, 'db> {
// async closures always return the type ascribed after the `->` (if present),
// and yield `()`.
let bound_return_ty = bound_sig.skip_binder().output();
- let bound_yield_ty = self.types.unit;
+ let bound_yield_ty = self.types.types.unit;
// rustc uses a special lang item type for the resume ty. I don't believe this can cause us problems.
- let resume_ty = self.types.unit;
+ let resume_ty = self.types.types.unit;
// FIXME: Infer the kind later if needed.
let closure_kind_ty = Ty::from_closure_kind(
@@ -155,26 +155,26 @@ impl<'db> InferenceContext<'_, 'db> {
let coroutine_captures_by_ref_ty = Ty::new_fn_ptr(
interner,
Binder::bind_with_vars(
- interner.mk_fn_sig([], self.types.unit, false, Safety::Safe, FnAbi::Rust),
- BoundVarKinds::new_from_iter(
- interner,
- [BoundVarKind::Region(BoundRegionKind::ClosureEnv)],
+ interner.mk_fn_sig(
+ [],
+ self.types.types.unit,
+ false,
+ Safety::Safe,
+ FnAbi::Rust,
),
+ self.types.coroutine_captures_by_ref_bound_var_kinds,
),
);
let closure_args = CoroutineClosureArgs::new(
interner,
CoroutineClosureArgsParts {
- parent_args,
+ parent_args: parent_args.as_slice(),
closure_kind_ty,
signature_parts_ty: Ty::new_fn_ptr(
interner,
bound_sig.map_bound(|sig| {
interner.mk_fn_sig(
- [
- resume_ty,
- Ty::new_tup_from_iter(interner, sig.inputs().iter()),
- ],
+ [resume_ty, Ty::new_tup(interner, sig.inputs())],
Ty::new_tup(interner, &[bound_yield_ty, bound_return_ty]),
sig.c_variadic,
sig.safety,
@@ -195,7 +195,7 @@ impl<'db> InferenceContext<'_, 'db> {
// Now go through the argument patterns
for (arg_pat, arg_ty) in args.iter().zip(bound_sig.skip_binder().inputs()) {
- self.infer_top_pat(*arg_pat, arg_ty, None);
+ self.infer_top_pat(*arg_pat, *arg_ty, None);
}
// FIXME: lift these out into a struct
@@ -668,7 +668,7 @@ impl<'db> InferenceContext<'_, 'db> {
assert!(!expected_sig.skip_binder().has_vars_bound_above(rustc_type_ir::INNERMOST));
let bound_sig = expected_sig.map_bound(|sig| {
self.interner().mk_fn_sig(
- sig.inputs(),
+ sig.inputs().iter().copied(),
sig.output(),
sig.c_variadic,
Safety::Safe,
@@ -744,9 +744,10 @@ impl<'db> InferenceContext<'_, 'db> {
// The liberated version of this signature should be a subtype
// of the liberated form of the expectation.
- for (supplied_ty, expected_ty) in
- iter::zip(supplied_sig.inputs(), expected_sigs.liberated_sig.inputs())
- {
+ for (supplied_ty, expected_ty) in iter::zip(
+ supplied_sig.inputs().iter().copied(),
+ expected_sigs.liberated_sig.inputs().iter().copied(),
+ ) {
// Check that E' = S'.
let cause = ObligationCause::new();
let InferOk { value: (), obligations } =
@@ -765,7 +766,8 @@ impl<'db> InferenceContext<'_, 'db> {
let inputs = supplied_sig
.inputs()
- .into_iter()
+ .iter()
+ .copied()
.map(|ty| table.infer_ctxt.resolve_vars_if_possible(ty));
expected_sigs.liberated_sig = table.interner().mk_fn_sig(