From 230c763648ad87e07d843a52c134b12d1b7397f4 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 6 Apr 2021 19:44:28 +0200 Subject: infer: remove `record_pat_field_resolutions` field Same as https://github.com/rust-analyzer/rust-analyzer/pull/8376, this can be computed from other data --- crates/hir/src/source_analyzer.rs | 12 ++++++++---- crates/hir_ty/src/infer.rs | 6 +----- crates/hir_ty/src/infer/pat.rs | 6 ------ 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index c013e78d9..ce6f3c008 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -185,12 +185,16 @@ impl SourceAnalyzer { pub(crate) fn resolve_record_pat_field( &self, - _db: &dyn HirDatabase, + db: &dyn HirDatabase, field: &ast::RecordPatField, ) -> Option { - let pat_id = self.pat_id(&field.pat()?)?; - let struct_field = self.infer.as_ref()?.record_pat_field_resolution(pat_id)?; - Some(struct_field.into()) + let field_name = field.field_name()?.as_name(); + let record_pat = ast::RecordPat::cast(field.syntax().parent().and_then(|p| p.parent())?)?; + let pat_id = self.pat_id(&record_pat.into())?; + let variant = self.infer.as_ref()?.variant_resolution_for_pat(pat_id)?; + let variant_data = variant.variant_data(db.upcast()); + let field = FieldId { parent: variant, local_id: variant_data.field(&field_name)? }; + Some(field.into()) } pub(crate) fn resolve_macro_call( diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index c63878e7a..efe9198cc 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs @@ -131,8 +131,7 @@ pub struct InferenceResult { method_resolutions: FxHashMap, /// For each field access expr, records the field it resolves to. field_resolutions: FxHashMap, - record_pat_field_resolutions: FxHashMap, - /// For each struct literal, records the variant it resolves to. + /// For each struct literal or pattern, records the variant it resolves to. variant_resolutions: FxHashMap, /// For each associated item record what it resolves to assoc_resolutions: FxHashMap, @@ -151,9 +150,6 @@ impl InferenceResult { pub fn field_resolution(&self, expr: ExprId) -> Option { self.field_resolutions.get(&expr).copied() } - pub fn record_pat_field_resolution(&self, pat: PatId) -> Option { - self.record_pat_field_resolutions.get(&pat).copied() - } pub fn variant_resolution_for_expr(&self, id: ExprId) -> Option { self.variant_resolutions.get(&id.into()).copied() } diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index 942f70edf..e4813c87c 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs @@ -7,7 +7,6 @@ use chalk_ir::Mutability; use hir_def::{ expr::{BindingAnnotation, Expr, Literal, Pat, PatId, RecordFieldPat}, path::Path, - FieldId, }; use hir_expand::name::Name; @@ -80,11 +79,6 @@ impl<'a> InferenceContext<'a> { let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); for subpat in subpats { let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name)); - if let Some(local_id) = matching_field { - let field_def = FieldId { parent: def.unwrap(), local_id }; - self.result.record_pat_field_resolutions.insert(subpat.pat, field_def); - } - let expected_ty = matching_field.map_or(self.err_ty(), |field| { field_tys[field].clone().substitute(&Interner, &substs) }); -- cgit v1.2.3