aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-04-06 18:44:28 +0100
committerJonas Schievink <[email protected]>2021-04-06 18:44:28 +0100
commit230c763648ad87e07d843a52c134b12d1b7397f4 (patch)
treecce18424094010e01c366703f4ed771a3e1dd479
parente6a1c9ca60c19bf3b02b302e21d9f9fd9bd8a466 (diff)
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
-rw-r--r--crates/hir/src/source_analyzer.rs12
-rw-r--r--crates/hir_ty/src/infer.rs6
-rw-r--r--crates/hir_ty/src/infer/pat.rs6
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 {
185 185
186 pub(crate) fn resolve_record_pat_field( 186 pub(crate) fn resolve_record_pat_field(
187 &self, 187 &self,
188 _db: &dyn HirDatabase, 188 db: &dyn HirDatabase,
189 field: &ast::RecordPatField, 189 field: &ast::RecordPatField,
190 ) -> Option<Field> { 190 ) -> Option<Field> {
191 let pat_id = self.pat_id(&field.pat()?)?; 191 let field_name = field.field_name()?.as_name();
192 let struct_field = self.infer.as_ref()?.record_pat_field_resolution(pat_id)?; 192 let record_pat = ast::RecordPat::cast(field.syntax().parent().and_then(|p| p.parent())?)?;
193 Some(struct_field.into()) 193 let pat_id = self.pat_id(&record_pat.into())?;
194 let variant = self.infer.as_ref()?.variant_resolution_for_pat(pat_id)?;
195 let variant_data = variant.variant_data(db.upcast());
196 let field = FieldId { parent: variant, local_id: variant_data.field(&field_name)? };
197 Some(field.into())
194 } 198 }
195 199
196 pub(crate) fn resolve_macro_call( 200 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 {
131 method_resolutions: FxHashMap<ExprId, FunctionId>, 131 method_resolutions: FxHashMap<ExprId, FunctionId>,
132 /// For each field access expr, records the field it resolves to. 132 /// For each field access expr, records the field it resolves to.
133 field_resolutions: FxHashMap<ExprId, FieldId>, 133 field_resolutions: FxHashMap<ExprId, FieldId>,
134 record_pat_field_resolutions: FxHashMap<PatId, FieldId>, 134 /// For each struct literal or pattern, records the variant it resolves to.
135 /// For each struct literal, records the variant it resolves to.
136 variant_resolutions: FxHashMap<ExprOrPatId, VariantId>, 135 variant_resolutions: FxHashMap<ExprOrPatId, VariantId>,
137 /// For each associated item record what it resolves to 136 /// For each associated item record what it resolves to
138 assoc_resolutions: FxHashMap<ExprOrPatId, AssocItemId>, 137 assoc_resolutions: FxHashMap<ExprOrPatId, AssocItemId>,
@@ -151,9 +150,6 @@ impl InferenceResult {
151 pub fn field_resolution(&self, expr: ExprId) -> Option<FieldId> { 150 pub fn field_resolution(&self, expr: ExprId) -> Option<FieldId> {
152 self.field_resolutions.get(&expr).copied() 151 self.field_resolutions.get(&expr).copied()
153 } 152 }
154 pub fn record_pat_field_resolution(&self, pat: PatId) -> Option<FieldId> {
155 self.record_pat_field_resolutions.get(&pat).copied()
156 }
157 pub fn variant_resolution_for_expr(&self, id: ExprId) -> Option<VariantId> { 153 pub fn variant_resolution_for_expr(&self, id: ExprId) -> Option<VariantId> {
158 self.variant_resolutions.get(&id.into()).copied() 154 self.variant_resolutions.get(&id.into()).copied()
159 } 155 }
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;
7use hir_def::{ 7use hir_def::{
8 expr::{BindingAnnotation, Expr, Literal, Pat, PatId, RecordFieldPat}, 8 expr::{BindingAnnotation, Expr, Literal, Pat, PatId, RecordFieldPat},
9 path::Path, 9 path::Path,
10 FieldId,
11}; 10};
12use hir_expand::name::Name; 11use hir_expand::name::Name;
13 12
@@ -80,11 +79,6 @@ impl<'a> InferenceContext<'a> {
80 let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); 79 let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default();
81 for subpat in subpats { 80 for subpat in subpats {
82 let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name)); 81 let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name));
83 if let Some(local_id) = matching_field {
84 let field_def = FieldId { parent: def.unwrap(), local_id };
85 self.result.record_pat_field_resolutions.insert(subpat.pat, field_def);
86 }
87
88 let expected_ty = matching_field.map_or(self.err_ty(), |field| { 82 let expected_ty = matching_field.map_or(self.err_ty(), |field| {
89 field_tys[field].clone().substitute(&Interner, &substs) 83 field_tys[field].clone().substitute(&Interner, &substs)
90 }); 84 });