aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/infer.rs5
-rw-r--r--crates/ra_hir/src/ty/infer/expr.rs28
2 files changed, 20 insertions, 13 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 2e744e5ec..0a9a83800 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -126,6 +126,8 @@ pub struct InferenceResult {
126 method_resolutions: FxHashMap<ExprId, Function>, 126 method_resolutions: FxHashMap<ExprId, Function>,
127 /// For each field access expr, records the field it resolves to. 127 /// For each field access expr, records the field it resolves to.
128 field_resolutions: FxHashMap<ExprId, StructField>, 128 field_resolutions: FxHashMap<ExprId, StructField>,
129 /// For each field in record literal, records the field it resolves to.
130 record_field_resolutions: FxHashMap<ExprId, StructField>,
129 /// For each struct literal, records the variant it resolves to. 131 /// For each struct literal, records the variant it resolves to.
130 variant_resolutions: FxHashMap<ExprOrPatId, VariantDef>, 132 variant_resolutions: FxHashMap<ExprOrPatId, VariantDef>,
131 /// For each associated item record what it resolves to 133 /// For each associated item record what it resolves to
@@ -143,6 +145,9 @@ impl InferenceResult {
143 pub fn field_resolution(&self, expr: ExprId) -> Option<StructField> { 145 pub fn field_resolution(&self, expr: ExprId) -> Option<StructField> {
144 self.field_resolutions.get(&expr).copied() 146 self.field_resolutions.get(&expr).copied()
145 } 147 }
148 pub fn record_field_resolution(&self, expr: ExprId) -> Option<StructField> {
149 self.record_field_resolutions.get(&expr).copied()
150 }
146 pub fn variant_resolution_for_expr(&self, id: ExprId) -> Option<VariantDef> { 151 pub fn variant_resolution_for_expr(&self, id: ExprId) -> Option<VariantDef> {
147 self.variant_resolutions.get(&id.into()).copied() 152 self.variant_resolutions.get(&id.into()).copied()
148 } 153 }
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs
index 20a7e9352..2996920c6 100644
--- a/crates/ra_hir/src/ty/infer/expr.rs
+++ b/crates/ra_hir/src/ty/infer/expr.rs
@@ -215,19 +215,21 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
215 215
216 let substs = ty.substs().unwrap_or_else(Substs::empty); 216 let substs = ty.substs().unwrap_or_else(Substs::empty);
217 for (field_idx, field) in fields.iter().enumerate() { 217 for (field_idx, field) in fields.iter().enumerate() {
218 let field_ty = def_id 218 let field_def = def_id.and_then(|it| match it.field(self.db, &field.name) {
219 .and_then(|it| match it.field(self.db, &field.name) { 219 Some(field) => Some(field),
220 Some(field) => Some(field), 220 None => {
221 None => { 221 self.push_diagnostic(InferenceDiagnostic::NoSuchField {
222 self.push_diagnostic(InferenceDiagnostic::NoSuchField { 222 expr: tgt_expr,
223 expr: tgt_expr, 223 field: field_idx,
224 field: field_idx, 224 });
225 }); 225 None
226 None 226 }
227 } 227 });
228 }) 228 if let Some(field_def) = field_def {
229 .map_or(Ty::Unknown, |field| field.ty(self.db)) 229 self.result.record_field_resolutions.insert(field.expr, field_def);
230 .subst(&substs); 230 }
231 let field_ty =
232 field_def.map_or(Ty::Unknown, |field| field.ty(self.db)).subst(&substs);
231 self.infer_expr_coerce(field.expr, &Expectation::has_type(field_ty)); 233 self.infer_expr_coerce(field.expr, &Expectation::has_type(field_ty));
232 } 234 }
233 if let Some(expr) = spread { 235 if let Some(expr) = spread {