diff options
author | Marcus Klaas de Vries <[email protected]> | 2019-01-18 14:38:11 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-19 12:37:26 +0000 |
commit | bcbfa2cc1146dfa23acb3e61f7ec053733a8fac1 (patch) | |
tree | 7586d897724f0bf75b466945c4f9f34cd59197d7 /crates/ra_hir/src/code_model_api.rs | |
parent | 4277f420aa947f0c0739506ec229da94e76ee67b (diff) |
Finish move of StructField for pattern type inference
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 860fd7539..11e919c1a 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -158,7 +158,7 @@ impl Module { | |||
158 | 158 | ||
159 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 159 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
160 | pub struct StructField { | 160 | pub struct StructField { |
161 | struct_: Struct, | 161 | parent: DefId, |
162 | name: Name, | 162 | name: Name, |
163 | } | 163 | } |
164 | 164 | ||
@@ -166,8 +166,9 @@ impl StructField { | |||
166 | pub fn name(&self) -> &Name { | 166 | pub fn name(&self) -> &Name { |
167 | &self.name | 167 | &self.name |
168 | } | 168 | } |
169 | |||
169 | pub fn ty(&self, db: &impl HirDatabase) -> Option<Ty> { | 170 | pub fn ty(&self, db: &impl HirDatabase) -> Option<Ty> { |
170 | db.type_for_field(self.struct_.def_id, self.name.clone()) | 171 | db.type_for_field(self.parent, self.name.clone()) |
171 | } | 172 | } |
172 | } | 173 | } |
173 | 174 | ||
@@ -191,7 +192,7 @@ impl Struct { | |||
191 | .fields() | 192 | .fields() |
192 | .iter() | 193 | .iter() |
193 | .map(|it| StructField { | 194 | .map(|it| StructField { |
194 | struct_: self.clone(), | 195 | parent: self.def_id, |
195 | name: it.name.clone(), | 196 | name: it.name.clone(), |
196 | }) | 197 | }) |
197 | .collect() | 198 | .collect() |
@@ -255,6 +256,17 @@ impl EnumVariant { | |||
255 | db.enum_variant_data(self.def_id).variant_data.clone() | 256 | db.enum_variant_data(self.def_id).variant_data.clone() |
256 | } | 257 | } |
257 | 258 | ||
259 | pub fn fields(&self, db: &impl HirDatabase) -> Vec<StructField> { | ||
260 | self.variant_data(db) | ||
261 | .fields() | ||
262 | .iter() | ||
263 | .map(|it| StructField { | ||
264 | parent: self.def_id, | ||
265 | name: it.name.clone(), | ||
266 | }) | ||
267 | .collect() | ||
268 | } | ||
269 | |||
258 | pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::EnumVariant>) { | 270 | pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::EnumVariant>) { |
259 | def_id_to_ast(db, self.def_id) | 271 | def_id_to_ast(db, self.def_id) |
260 | } | 272 | } |