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.rs46
1 files changed, 22 insertions, 24 deletions
diff --git a/crates/hir-ty/src/infer/closure.rs b/crates/hir-ty/src/infer/closure.rs
index 118b9c0149..572df8f713 100644
--- a/crates/hir-ty/src/infer/closure.rs
+++ b/crates/hir-ty/src/infer/closure.rs
@@ -27,14 +27,14 @@ use crate::{
static_lifetime, to_chalk_trait_id,
traits::FnTrait,
utils::{self, generics, Generics},
- Adjust, Adjustment, Binders, BindingMode, ChalkTraitId, ClosureId, DynTy, FnPointer, FnSig,
- Interner, Substitution, Ty, TyExt,
+ Adjust, Adjustment, Binders, BindingMode, ChalkTraitId, ClosureId, DynTy, FnAbi, FnPointer,
+ FnSig, Interner, Substitution, Ty, TyExt,
};
use super::{Expectation, InferenceContext};
impl InferenceContext<'_> {
- // This function handles both closures and generators.
+ // This function handles both closures and coroutines.
pub(super) fn deduce_closure_type_from_expectations(
&mut self,
closure_expr: ExprId,
@@ -50,8 +50,8 @@ impl InferenceContext<'_> {
// Deduction from where-clauses in scope, as well as fn-pointer coercion are handled here.
let _ = self.coerce(Some(closure_expr), closure_ty, &expected_ty);
- // Generators are not Fn* so return early.
- if matches!(closure_ty.kind(Interner), TyKind::Generator(..)) {
+ // Coroutines are not Fn* so return early.
+ if matches!(closure_ty.kind(Interner), TyKind::Coroutine(..)) {
return;
}
@@ -98,7 +98,11 @@ impl InferenceContext<'_> {
cov_mark::hit!(dyn_fn_param_informs_call_site_closure_signature);
return Some(FnPointer {
num_binders: bound.len(Interner),
- sig: FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic: false },
+ sig: FnSig {
+ abi: FnAbi::RustCall,
+ safety: chalk_ir::Safety::Safe,
+ variadic: false,
+ },
substitution: FnSubst(Substitution::from_iter(Interner, sig_tys)),
});
}
@@ -138,13 +142,10 @@ impl HirPlace {
mut current_capture: CaptureKind,
len: usize,
) -> CaptureKind {
- match current_capture {
- CaptureKind::ByRef(BorrowKind::Mut { .. }) => {
- if self.projections[len..].iter().any(|it| *it == ProjectionElem::Deref) {
- current_capture = CaptureKind::ByRef(BorrowKind::Unique);
- }
+ if let CaptureKind::ByRef(BorrowKind::Mut { .. }) = current_capture {
+ if self.projections[len..].iter().any(|it| *it == ProjectionElem::Deref) {
+ current_capture = CaptureKind::ByRef(BorrowKind::Unique);
}
- _ => (),
}
current_capture
}
@@ -330,12 +331,10 @@ impl InferenceContext<'_> {
match &self.body[tgt_expr] {
Expr::Path(p) => {
let resolver = resolver_for_expr(self.db.upcast(), self.owner, tgt_expr);
- if let Some(r) = resolver.resolve_path_in_value_ns(self.db.upcast(), p) {
- if let ResolveValueResult::ValueNs(v, _) = r {
- if let ValueNs::LocalBinding(b) = v {
- return Some(HirPlace { local: b, projections: vec![] });
- }
- }
+ if let Some(ResolveValueResult::ValueNs(ValueNs::LocalBinding(b), _)) =
+ resolver.resolve_path_in_value_ns(self.db.upcast(), p)
+ {
+ return Some(HirPlace { local: b, projections: vec![] });
}
}
Expr::Field { expr, name: _ } => {
@@ -666,7 +665,7 @@ impl InferenceContext<'_> {
| Pat::Or(_) => (),
Pat::TupleStruct { .. } | Pat::Record { .. } => {
if let Some(variant) = self.result.variant_resolution_for_pat(p) {
- let adt = variant.adt_id();
+ let adt = variant.adt_id(self.db.upcast());
let is_multivariant = match adt {
hir_def::AdtId::EnumId(e) => self.db.enum_data(e).variants.len() != 1,
_ => false,
@@ -815,8 +814,7 @@ impl InferenceContext<'_> {
.iter()
.cloned()
.chain((0..cnt).map(|_| ProjectionElem::Deref))
- .collect::<Vec<_>>()
- .into();
+ .collect::<Vec<_>>();
match &self.body[pat] {
Pat::Missing | Pat::Wild => (),
Pat::Tuple { args, ellipsis } => {
@@ -858,7 +856,7 @@ impl InferenceContext<'_> {
};
let mut p = place.clone();
p.projections.push(ProjectionElem::Field(Either::Left(FieldId {
- parent: variant.into(),
+ parent: variant,
local_id,
})));
self.consume_with_pat(p, arg);
@@ -902,7 +900,7 @@ impl InferenceContext<'_> {
for (arg, (i, _)) in it {
let mut p = place.clone();
p.projections.push(ProjectionElem::Field(Either::Left(FieldId {
- parent: variant.into(),
+ parent: variant,
local_id: i,
})));
self.consume_with_pat(p, *arg);
@@ -1007,7 +1005,7 @@ impl InferenceContext<'_> {
let mut deferred_closures = mem::take(&mut self.deferred_closures);
let mut dependents_count: FxHashMap<ClosureId, usize> =
deferred_closures.keys().map(|it| (*it, 0)).collect();
- for (_, deps) in &self.closure_dependencies {
+ for deps in self.closure_dependencies.values() {
for dep in deps {
*dependents_count.entry(*dep).or_default() += 1;
}