From 586acef5283e78f19e5e9daf4e8aac40e2a9ff16 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Nov 2019 22:44:24 +0300 Subject: Simplify ADT fields --- crates/ra_hir/src/code_model.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'crates/ra_hir/src/code_model.rs') 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 { impl StructField { pub fn name(&self, db: &impl HirDatabase) -> Name { - self.parent.variant_data(db).fields().unwrap()[self.id].name.clone() + self.parent.variant_data(db).fields()[self.id].name.clone() } pub fn ty(&self, db: &impl HirDatabase) -> Ty { @@ -335,8 +335,7 @@ impl Struct { db.struct_data(self.id.into()) .variant_data .fields() - .into_iter() - .flat_map(|it| it.iter()) + .iter() .map(|(id, _)| StructField { parent: self.into(), id }) .collect() } @@ -345,8 +344,7 @@ impl Struct { db.struct_data(self.id.into()) .variant_data .fields() - .into_iter() - .flat_map(|it| it.iter()) + .iter() .find(|(_id, data)| data.name == *name) .map(|(id, _)| StructField { parent: self.into(), id }) } @@ -443,8 +441,7 @@ impl EnumVariant { pub fn fields(self, db: &impl HirDatabase) -> Vec { self.variant_data(db) .fields() - .into_iter() - .flat_map(|it| it.iter()) + .iter() .map(|(id, _)| StructField { parent: self.into(), id }) .collect() } @@ -452,8 +449,7 @@ impl EnumVariant { pub fn field(self, db: &impl HirDatabase, name: &Name) -> Option { self.variant_data(db) .fields() - .into_iter() - .flat_map(|it| it.iter()) + .iter() .find(|(_id, data)| data.name == *name) .map(|(id, _)| StructField { parent: self.into(), id }) } -- cgit v1.2.3