aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/infer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/infer.rs')
-rw-r--r--crates/ra_hir/src/ty/infer.rs22
1 files changed, 15 insertions, 7 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index a82dff711..594c5bc79 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -113,7 +113,8 @@ pub struct InferenceResult {
113 method_resolutions: FxHashMap<ExprId, Function>, 113 method_resolutions: FxHashMap<ExprId, Function>,
114 /// For each field access expr, records the field it resolves to. 114 /// For each field access expr, records the field it resolves to.
115 field_resolutions: FxHashMap<ExprId, StructField>, 115 field_resolutions: FxHashMap<ExprId, StructField>,
116 variant_resolutions: FxHashMap<ExprId, VariantDef>, 116 /// For each struct literal, records the variant it resolves to.
117 variant_resolutions: FxHashMap<ExprOrPatId, VariantDef>,
117 /// For each associated item record what it resolves to 118 /// For each associated item record what it resolves to
118 assoc_resolutions: FxHashMap<ExprOrPatId, ImplItem>, 119 assoc_resolutions: FxHashMap<ExprOrPatId, ImplItem>,
119 diagnostics: Vec<InferenceDiagnostic>, 120 diagnostics: Vec<InferenceDiagnostic>,
@@ -128,8 +129,11 @@ impl InferenceResult {
128 pub fn field_resolution(&self, expr: ExprId) -> Option<StructField> { 129 pub fn field_resolution(&self, expr: ExprId) -> Option<StructField> {
129 self.field_resolutions.get(&expr).copied() 130 self.field_resolutions.get(&expr).copied()
130 } 131 }
131 pub fn variant_resolution(&self, expr: ExprId) -> Option<VariantDef> { 132 pub fn variant_resolution_for_expr(&self, id: ExprId) -> Option<VariantDef> {
132 self.variant_resolutions.get(&expr).copied() 133 self.variant_resolutions.get(&id.into()).copied()
134 }
135 pub fn variant_resolution_for_pat(&self, id: PatId) -> Option<VariantDef> {
136 self.variant_resolutions.get(&id.into()).copied()
133 } 137 }
134 pub fn assoc_resolutions_for_expr(&self, id: ExprId) -> Option<ImplItem> { 138 pub fn assoc_resolutions_for_expr(&self, id: ExprId) -> Option<ImplItem> {
135 self.assoc_resolutions.get(&id.into()).copied() 139 self.assoc_resolutions.get(&id.into()).copied()
@@ -218,8 +222,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
218 self.result.field_resolutions.insert(expr, field); 222 self.result.field_resolutions.insert(expr, field);
219 } 223 }
220 224
221 fn write_variant_resolution(&mut self, expr: ExprId, variant: VariantDef) { 225 fn write_variant_resolution(&mut self, id: ExprOrPatId, variant: VariantDef) {
222 self.result.variant_resolutions.insert(expr, variant); 226 self.result.variant_resolutions.insert(id, variant);
223 } 227 }
224 228
225 fn write_assoc_resolution(&mut self, id: ExprOrPatId, item: ImplItem) { 229 fn write_assoc_resolution(&mut self, id: ExprOrPatId, item: ImplItem) {
@@ -678,8 +682,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
678 subpats: &[FieldPat], 682 subpats: &[FieldPat],
679 expected: &Ty, 683 expected: &Ty,
680 default_bm: BindingMode, 684 default_bm: BindingMode,
685 id: PatId,
681 ) -> Ty { 686 ) -> Ty {
682 let (ty, def) = self.resolve_variant(path); 687 let (ty, def) = self.resolve_variant(path);
688 if let Some(variant) = def {
689 self.write_variant_resolution(id.into(), variant);
690 }
683 691
684 self.unify(&ty, expected); 692 self.unify(&ty, expected);
685 693
@@ -762,7 +770,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
762 self.infer_tuple_struct_pat(p.as_ref(), subpats, expected, default_bm) 770 self.infer_tuple_struct_pat(p.as_ref(), subpats, expected, default_bm)
763 } 771 }
764 Pat::Struct { path: ref p, args: ref fields } => { 772 Pat::Struct { path: ref p, args: ref fields } => {
765 self.infer_struct_pat(p.as_ref(), fields, expected, default_bm) 773 self.infer_struct_pat(p.as_ref(), fields, expected, default_bm, pat)
766 } 774 }
767 Pat::Path(path) => { 775 Pat::Path(path) => {
768 // FIXME use correct resolver for the surrounding expression 776 // FIXME use correct resolver for the surrounding expression
@@ -1064,7 +1072,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1064 Expr::StructLit { path, fields, spread } => { 1072 Expr::StructLit { path, fields, spread } => {
1065 let (ty, def_id) = self.resolve_variant(path.as_ref()); 1073 let (ty, def_id) = self.resolve_variant(path.as_ref());
1066 if let Some(variant) = def_id { 1074 if let Some(variant) = def_id {
1067 self.write_variant_resolution(tgt_expr, variant); 1075 self.write_variant_resolution(tgt_expr.into(), variant);
1068 } 1076 }
1069 1077
1070 let substs = ty.substs().unwrap_or_else(Substs::empty); 1078 let substs = ty.substs().unwrap_or_else(Substs::empty);