From 63e3ea38d3ff7ab69b968e8962f33e82a4f978fb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Nov 2019 20:06:55 +0300 Subject: Don't redo field resolution in the IDE --- crates/ra_hir/src/ty/infer/expr.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'crates/ra_hir/src/ty/infer') 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> { let substs = ty.substs().unwrap_or_else(Substs::empty); for (field_idx, field) in fields.iter().enumerate() { - let field_ty = def_id - .and_then(|it| match it.field(self.db, &field.name) { - Some(field) => Some(field), - None => { - self.push_diagnostic(InferenceDiagnostic::NoSuchField { - expr: tgt_expr, - field: field_idx, - }); - None - } - }) - .map_or(Ty::Unknown, |field| field.ty(self.db)) - .subst(&substs); + let field_def = def_id.and_then(|it| match it.field(self.db, &field.name) { + Some(field) => Some(field), + None => { + self.push_diagnostic(InferenceDiagnostic::NoSuchField { + expr: tgt_expr, + field: field_idx, + }); + None + } + }); + if let Some(field_def) = field_def { + self.result.record_field_resolutions.insert(field.expr, field_def); + } + let field_ty = + field_def.map_or(Ty::Unknown, |field| field.ty(self.db)).subst(&substs); self.infer_expr_coerce(field.expr, &Expectation::has_type(field_ty)); } if let Some(expr) = spread { -- cgit v1.2.3