diff options
author | Aleksey Kladov <[email protected]> | 2019-11-24 19:44:24 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-24 19:44:24 +0000 |
commit | 586acef5283e78f19e5e9daf4e8aac40e2a9ff16 (patch) | |
tree | 7daaf3dc8595dc8f431e84db6469c7fa02f6e680 /crates/ra_hir/src/code_model.rs | |
parent | 09389ed1d43c244352cecbd78c8685480d60157d (diff) |
Simplify ADT fields
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 96a5cc857..ab0544a4c 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -301,7 +301,7 @@ pub enum FieldSource { | |||
301 | 301 | ||
302 | impl StructField { | 302 | impl StructField { |
303 | pub fn name(&self, db: &impl HirDatabase) -> Name { | 303 | pub fn name(&self, db: &impl HirDatabase) -> Name { |
304 | self.parent.variant_data(db).fields().unwrap()[self.id].name.clone() | 304 | self.parent.variant_data(db).fields()[self.id].name.clone() |
305 | } | 305 | } |
306 | 306 | ||
307 | pub fn ty(&self, db: &impl HirDatabase) -> Ty { | 307 | pub fn ty(&self, db: &impl HirDatabase) -> Ty { |
@@ -335,8 +335,7 @@ impl Struct { | |||
335 | db.struct_data(self.id.into()) | 335 | db.struct_data(self.id.into()) |
336 | .variant_data | 336 | .variant_data |
337 | .fields() | 337 | .fields() |
338 | .into_iter() | 338 | .iter() |
339 | .flat_map(|it| it.iter()) | ||
340 | .map(|(id, _)| StructField { parent: self.into(), id }) | 339 | .map(|(id, _)| StructField { parent: self.into(), id }) |
341 | .collect() | 340 | .collect() |
342 | } | 341 | } |
@@ -345,8 +344,7 @@ impl Struct { | |||
345 | db.struct_data(self.id.into()) | 344 | db.struct_data(self.id.into()) |
346 | .variant_data | 345 | .variant_data |
347 | .fields() | 346 | .fields() |
348 | .into_iter() | 347 | .iter() |
349 | .flat_map(|it| it.iter()) | ||
350 | .find(|(_id, data)| data.name == *name) | 348 | .find(|(_id, data)| data.name == *name) |
351 | .map(|(id, _)| StructField { parent: self.into(), id }) | 349 | .map(|(id, _)| StructField { parent: self.into(), id }) |
352 | } | 350 | } |
@@ -443,8 +441,7 @@ impl EnumVariant { | |||
443 | pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> { | 441 | pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> { |
444 | self.variant_data(db) | 442 | self.variant_data(db) |
445 | .fields() | 443 | .fields() |
446 | .into_iter() | 444 | .iter() |
447 | .flat_map(|it| it.iter()) | ||
448 | .map(|(id, _)| StructField { parent: self.into(), id }) | 445 | .map(|(id, _)| StructField { parent: self.into(), id }) |
449 | .collect() | 446 | .collect() |
450 | } | 447 | } |
@@ -452,8 +449,7 @@ impl EnumVariant { | |||
452 | pub fn field(self, db: &impl HirDatabase, name: &Name) -> Option<StructField> { | 449 | pub fn field(self, db: &impl HirDatabase, name: &Name) -> Option<StructField> { |
453 | self.variant_data(db) | 450 | self.variant_data(db) |
454 | .fields() | 451 | .fields() |
455 | .into_iter() | 452 | .iter() |
456 | .flat_map(|it| it.iter()) | ||
457 | .find(|(_id, data)| data.name == *name) | 453 | .find(|(_id, data)| data.name == *name) |
458 | .map(|(id, _)| StructField { parent: self.into(), id }) | 454 | .map(|(id, _)| StructField { parent: self.into(), id }) |
459 | } | 455 | } |