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.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs
index f2c860c9eb..db16899d9f 100644
--- a/crates/hir-ty/src/infer.rs
+++ b/crates/hir-ty/src/infer.rs
@@ -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;