Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/infer.rs')
-rw-r--r--crates/hir-ty/src/infer.rs35
1 files changed, 34 insertions, 1 deletions
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs
index 4f41af0b4e..6859c2d9c3 100644
--- a/crates/hir-ty/src/infer.rs
+++ b/crates/hir-ty/src/infer.rs
@@ -228,7 +228,7 @@ pub enum InferenceDiagnostic {
id: ExprOrPatId,
},
UnresolvedIdent {
- expr: ExprId,
+ id: ExprOrPatId,
},
// FIXME: This should be emitted in body lowering
BreakOutsideOfLoop {
@@ -482,12 +482,27 @@ impl InferenceResult {
pub fn variant_resolution_for_pat(&self, id: PatId) -> Option<VariantId> {
self.variant_resolutions.get(&id.into()).copied()
}
+ pub fn variant_resolution_for_expr_or_pat(&self, id: ExprOrPatId) -> Option<VariantId> {
+ match id {
+ ExprOrPatId::ExprId(id) => self.variant_resolution_for_expr(id),
+ ExprOrPatId::PatId(id) => self.variant_resolution_for_pat(id),
+ }
+ }
pub fn assoc_resolutions_for_expr(&self, id: ExprId) -> Option<(AssocItemId, Substitution)> {
self.assoc_resolutions.get(&id.into()).cloned()
}
pub fn assoc_resolutions_for_pat(&self, id: PatId) -> Option<(AssocItemId, Substitution)> {
self.assoc_resolutions.get(&id.into()).cloned()
}
+ pub fn assoc_resolutions_for_expr_or_pat(
+ &self,
+ id: ExprOrPatId,
+ ) -> Option<(AssocItemId, Substitution)> {
+ match id {
+ ExprOrPatId::ExprId(id) => self.assoc_resolutions_for_expr(id),
+ ExprOrPatId::PatId(id) => self.assoc_resolutions_for_pat(id),
+ }
+ }
pub fn type_mismatch_for_expr(&self, expr: ExprId) -> Option<&TypeMismatch> {
self.type_mismatches.get(&expr.into())
}
@@ -506,6 +521,12 @@ impl InferenceResult {
pub fn closure_info(&self, closure: &ClosureId) -> &(Vec<CapturedItem>, FnTrait) {
self.closure_info.get(closure).unwrap()
}
+ pub fn type_of_expr_or_pat(&self, id: ExprOrPatId) -> Option<&Ty> {
+ match id {
+ ExprOrPatId::ExprId(id) => self.type_of_expr.get(id),
+ ExprOrPatId::PatId(id) => self.type_of_pat.get(id),
+ }
+ }
}
impl Index<ExprId> for InferenceResult {
@@ -524,6 +545,14 @@ impl Index<PatId> for InferenceResult {
}
}
+impl Index<ExprOrPatId> for InferenceResult {
+ type Output = Ty;
+
+ fn index(&self, id: ExprOrPatId) -> &Ty {
+ self.type_of_expr_or_pat(id).unwrap_or(&self.standard_types.unknown)
+ }
+}
+
impl Index<BindingId> for InferenceResult {
type Output = Ty;
@@ -561,6 +590,9 @@ pub(crate) struct InferenceContext<'a> {
diverges: Diverges,
breakables: Vec<BreakableContext>,
+ /// Whether we are inside the pattern of a destructuring assignment.
+ inside_assignment: bool,
+
deferred_cast_checks: Vec<CastCheck>,
// fields related to closure capture
@@ -656,6 +688,7 @@ impl<'a> InferenceContext<'a> {
current_closure: None,
deferred_closures: FxHashMap::default(),
closure_dependencies: FxHashMap::default(),
+ inside_assignment: false,
}
}