diff options
author | Aleksey Kladov <[email protected]> | 2019-11-27 13:25:01 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-27 13:25:01 +0000 |
commit | 9fa46ff5c67bd1809cc748f6fc0e93d7c9be3fdb (patch) | |
tree | 8a6e1440ae2efc86a53aa77f65bdfad6cff00b0d /crates/ra_hir/src/ty/infer/pat.rs | |
parent | 17680f6060be1abe8f021538aeff0a95e9c569da (diff) |
Use Id for variats
Diffstat (limited to 'crates/ra_hir/src/ty/infer/pat.rs')
-rw-r--r-- | crates/ra_hir/src/ty/infer/pat.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/crates/ra_hir/src/ty/infer/pat.rs b/crates/ra_hir/src/ty/infer/pat.rs index 6dbf03eb2..a14774607 100644 --- a/crates/ra_hir/src/ty/infer/pat.rs +++ b/crates/ra_hir/src/ty/infer/pat.rs | |||
@@ -14,7 +14,7 @@ use test_utils::tested_by; | |||
14 | use super::{BindingMode, InferenceContext}; | 14 | use super::{BindingMode, InferenceContext}; |
15 | use crate::{ | 15 | use crate::{ |
16 | db::HirDatabase, | 16 | db::HirDatabase, |
17 | ty::{Substs, Ty, TypeCtor, TypeWalk}, | 17 | ty::{utils::variant_data, Substs, Ty, TypeCtor, TypeWalk}, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { | 20 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { |
@@ -26,16 +26,18 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
26 | default_bm: BindingMode, | 26 | default_bm: BindingMode, |
27 | ) -> Ty { | 27 | ) -> Ty { |
28 | let (ty, def) = self.resolve_variant(path); | 28 | let (ty, def) = self.resolve_variant(path); |
29 | 29 | let var_data = def.map(|it| variant_data(self.db, it)); | |
30 | self.unify(&ty, expected); | 30 | self.unify(&ty, expected); |
31 | 31 | ||
32 | let substs = ty.substs().unwrap_or_else(Substs::empty); | 32 | let substs = ty.substs().unwrap_or_else(Substs::empty); |
33 | 33 | ||
34 | let field_tys = def.map(|it| self.db.field_types(it.into())).unwrap_or_default(); | 34 | let field_tys = def.map(|it| self.db.field_types(it.into())).unwrap_or_default(); |
35 | |||
35 | for (i, &subpat) in subpats.iter().enumerate() { | 36 | for (i, &subpat) in subpats.iter().enumerate() { |
36 | let expected_ty = def | 37 | let expected_ty = var_data |
37 | .and_then(|d| d.field(self.db, &Name::new_tuple_field(i))) | 38 | .as_ref() |
38 | .map_or(Ty::Unknown, |field| field_tys[field.id].clone()) | 39 | .and_then(|d| d.field(&Name::new_tuple_field(i))) |
40 | .map_or(Ty::Unknown, |field| field_tys[field].clone()) | ||
39 | .subst(&substs); | 41 | .subst(&substs); |
40 | let expected_ty = self.normalize_associated_types_in(expected_ty); | 42 | let expected_ty = self.normalize_associated_types_in(expected_ty); |
41 | self.infer_pat(subpat, &expected_ty, default_bm); | 43 | self.infer_pat(subpat, &expected_ty, default_bm); |
@@ -53,6 +55,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
53 | id: PatId, | 55 | id: PatId, |
54 | ) -> Ty { | 56 | ) -> Ty { |
55 | let (ty, def) = self.resolve_variant(path); | 57 | let (ty, def) = self.resolve_variant(path); |
58 | let var_data = def.map(|it| variant_data(self.db, it)); | ||
56 | if let Some(variant) = def { | 59 | if let Some(variant) = def { |
57 | self.write_variant_resolution(id.into(), variant); | 60 | self.write_variant_resolution(id.into(), variant); |
58 | } | 61 | } |
@@ -63,10 +66,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
63 | 66 | ||
64 | let field_tys = def.map(|it| self.db.field_types(it.into())).unwrap_or_default(); | 67 | let field_tys = def.map(|it| self.db.field_types(it.into())).unwrap_or_default(); |
65 | for subpat in subpats { | 68 | for subpat in subpats { |
66 | let matching_field = def.and_then(|it| it.field(self.db, &subpat.name)); | 69 | let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name)); |
67 | let expected_ty = matching_field | 70 | let expected_ty = |
68 | .map_or(Ty::Unknown, |field| field_tys[field.id].clone()) | 71 | matching_field.map_or(Ty::Unknown, |field| field_tys[field].clone()).subst(&substs); |
69 | .subst(&substs); | ||
70 | let expected_ty = self.normalize_associated_types_in(expected_ty); | 72 | let expected_ty = self.normalize_associated_types_in(expected_ty); |
71 | self.infer_pat(subpat.pat, &expected_ty, default_bm); | 73 | self.infer_pat(subpat.pat, &expected_ty, default_bm); |
72 | } | 74 | } |