aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/code_model.rs14
-rw-r--r--crates/ra_hir/src/from_source.rs3
-rw-r--r--crates/ra_hir/src/ty/lower.rs16
3 files changed, 11 insertions, 22 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
302impl StructField { 302impl 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 }
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index 72d059a27..1e7c22774 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -200,8 +200,7 @@ impl FromSource for StructField {
200 variant_def 200 variant_def
201 .variant_data(db) 201 .variant_data(db)
202 .fields() 202 .fields()
203 .into_iter() 203 .iter()
204 .flat_map(|it| it.iter())
205 .map(|(id, _)| StructField { parent: variant_def, id }) 204 .map(|(id, _)| StructField { parent: variant_def, id })
206 .find(|f| f.source(db) == src) 205 .find(|f| f.source(db) == src)
207 } 206 }
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index 2272510e8..2b40cb07d 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -557,7 +557,7 @@ pub(crate) fn type_for_field(db: &impl HirDatabase, field: StructField) -> Ty {
557 VariantDef::EnumVariant(it) => it.parent.id.resolver(db), 557 VariantDef::EnumVariant(it) => it.parent.id.resolver(db),
558 }; 558 };
559 let var_data = parent_def.variant_data(db); 559 let var_data = parent_def.variant_data(db);
560 let type_ref = &var_data.fields().unwrap()[field.id].type_ref; 560 let type_ref = &var_data.fields()[field.id].type_ref;
561 Ty::from_hir(db, &resolver, type_ref) 561 Ty::from_hir(db, &resolver, type_ref)
562} 562}
563 563
@@ -696,10 +696,7 @@ impl From<Option<BuiltinFloat>> for Uncertain<FloatTy> {
696 696
697fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> FnSig { 697fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> FnSig {
698 let struct_data = db.struct_data(def.id.into()); 698 let struct_data = db.struct_data(def.id.into());
699 let fields = match struct_data.variant_data.fields() { 699 let fields = struct_data.variant_data.fields();
700 Some(fields) => fields,
701 None => panic!("fn_sig_for_struct_constructor called on unit struct"),
702 };
703 let resolver = def.id.resolver(db); 700 let resolver = def.id.resolver(db);
704 let params = fields 701 let params = fields
705 .iter() 702 .iter()
@@ -712,7 +709,7 @@ fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> FnSig {
712/// Build the type of a tuple struct constructor. 709/// Build the type of a tuple struct constructor.
713fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty { 710fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty {
714 let struct_data = db.struct_data(def.id.into()); 711 let struct_data = db.struct_data(def.id.into());
715 if struct_data.variant_data.fields().is_none() { 712 if struct_data.variant_data.is_unit() {
716 return type_for_adt(db, def); // Unit struct 713 return type_for_adt(db, def); // Unit struct
717 } 714 }
718 let generics = db.generic_params(def.id.into()); 715 let generics = db.generic_params(def.id.into());
@@ -722,10 +719,7 @@ fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty {
722 719
723fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> FnSig { 720fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> FnSig {
724 let var_data = def.variant_data(db); 721 let var_data = def.variant_data(db);
725 let fields = match var_data.fields() { 722 let fields = var_data.fields();
726 Some(fields) => fields,
727 None => panic!("fn_sig_for_enum_variant_constructor called for unit variant"),
728 };
729 let resolver = def.parent.id.resolver(db); 723 let resolver = def.parent.id.resolver(db);
730 let params = fields 724 let params = fields
731 .iter() 725 .iter()
@@ -740,7 +734,7 @@ fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant)
740/// Build the type of a tuple enum variant constructor. 734/// Build the type of a tuple enum variant constructor.
741fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> Ty { 735fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> Ty {
742 let var_data = def.variant_data(db); 736 let var_data = def.variant_data(db);
743 if var_data.fields().is_none() { 737 if var_data.is_unit() {
744 return type_for_adt(db, def.parent_enum(db)); // Unit variant 738 return type_for_adt(db, def.parent_enum(db)); // Unit variant
745 } 739 }
746 let generics = db.generic_params(def.parent_enum(db).id.into()); 740 let generics = db.generic_params(def.parent_enum(db).id.into());