diff options
Diffstat (limited to 'crates/hir_ty/src/infer.rs')
-rw-r--r-- | crates/hir_ty/src/infer.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index bf2da2d4a..0ee851a74 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs | |||
@@ -137,8 +137,12 @@ pub struct InferenceResult { | |||
137 | assoc_resolutions: FxHashMap<ExprOrPatId, AssocItemId>, | 137 | assoc_resolutions: FxHashMap<ExprOrPatId, AssocItemId>, |
138 | diagnostics: Vec<InferenceDiagnostic>, | 138 | diagnostics: Vec<InferenceDiagnostic>, |
139 | pub type_of_expr: ArenaMap<ExprId, Ty>, | 139 | pub type_of_expr: ArenaMap<ExprId, Ty>, |
140 | /// For each pattern record the type it resolves to. | ||
141 | /// | ||
142 | /// **Note**: When a pattern type is resolved it may still contain | ||
143 | /// unresolved or missing subpatterns or subpatterns of mismatched types. | ||
140 | pub type_of_pat: ArenaMap<PatId, Ty>, | 144 | pub type_of_pat: ArenaMap<PatId, Ty>, |
141 | pub(super) type_mismatches: ArenaMap<ExprId, TypeMismatch>, | 145 | type_mismatches: FxHashMap<ExprOrPatId, TypeMismatch>, |
142 | /// Interned Unknown to return references to. | 146 | /// Interned Unknown to return references to. |
143 | standard_types: InternedStandardTypes, | 147 | standard_types: InternedStandardTypes, |
144 | } | 148 | } |
@@ -163,7 +167,22 @@ impl InferenceResult { | |||
163 | self.assoc_resolutions.get(&id.into()).copied() | 167 | self.assoc_resolutions.get(&id.into()).copied() |
164 | } | 168 | } |
165 | pub fn type_mismatch_for_expr(&self, expr: ExprId) -> Option<&TypeMismatch> { | 169 | pub fn type_mismatch_for_expr(&self, expr: ExprId) -> Option<&TypeMismatch> { |
166 | self.type_mismatches.get(expr) | 170 | self.type_mismatches.get(&expr.into()) |
171 | } | ||
172 | pub fn type_mismatch_for_pat(&self, pat: PatId) -> Option<&TypeMismatch> { | ||
173 | self.type_mismatches.get(&pat.into()) | ||
174 | } | ||
175 | pub fn expr_type_mismatches(&self) -> impl Iterator<Item = (ExprId, &TypeMismatch)> { | ||
176 | self.type_mismatches.iter().filter_map(|(expr_or_pat, mismatch)| match *expr_or_pat { | ||
177 | ExprOrPatId::ExprId(expr) => Some((expr, mismatch)), | ||
178 | _ => None, | ||
179 | }) | ||
180 | } | ||
181 | pub fn pat_type_mismatches(&self) -> impl Iterator<Item = (PatId, &TypeMismatch)> { | ||
182 | self.type_mismatches.iter().filter_map(|(expr_or_pat, mismatch)| match *expr_or_pat { | ||
183 | ExprOrPatId::PatId(pat) => Some((pat, mismatch)), | ||
184 | _ => None, | ||
185 | }) | ||
167 | } | 186 | } |
168 | pub fn add_diagnostics( | 187 | pub fn add_diagnostics( |
169 | &self, | 188 | &self, |