diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-24 19:45:08 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-24 19:45:08 +0000 |
commit | f16cff3cad931d48a5516b2aec468cfddbed7dd1 (patch) | |
tree | 7daaf3dc8595dc8f431e84db6469c7fa02f6e680 /crates/ra_hir/src/ty/lower.rs | |
parent | 09389ed1d43c244352cecbd78c8685480d60157d (diff) | |
parent | 586acef5283e78f19e5e9daf4e8aac40e2a9ff16 (diff) |
Merge #2393
2393: Simplify ADT fields r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty/lower.rs')
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 16 |
1 files changed, 5 insertions, 11 deletions
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 | ||
697 | fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> FnSig { | 697 | fn 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. |
713 | fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty { | 710 | fn 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 | ||
723 | fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> FnSig { | 720 | fn 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. |
741 | fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> Ty { | 735 | fn 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()); |