aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-17 10:54:32 +0000
committerGitHub <[email protected]>2020-02-17 10:54:32 +0000
commitfcf15cc05afaeda6880664777ff2a3db342ea088 (patch)
treeac34e90a9884d7166daa5022ea402196483c26c0 /crates/ra_hir_ty
parent334f53465f5baf5094844ab3ca2d28e477d07b24 (diff)
parent0e260aa6b15d9dc8c067adb05f3774aec3fb66ec (diff)
Merge #3169
3169: Show record field names in Enum completion r=flodiebold a=adamrk Adresses https://github.com/rust-analyzer/rust-analyzer/issues/2947. Previously the details shown when autocompleting an Enum variant would look like the variant was a tuple even if it was a record: ![2020-02-16-15:59:32_crop](https://user-images.githubusercontent.com/16367467/74607233-64f21980-50d7-11ea-99db-e973e29c71d7.png) This change will show the names of the fields for a record and use curly braces instead of parentheses: ![2020-02-16-15:33:00_crop](https://user-images.githubusercontent.com/16367467/74607251-8ce17d00-50d7-11ea-9d4d-38d198a4aec0.png) This required exposing the type `adt::StructKind` from `ra_hir` and adding a function ``` kind(self, db: &impl HirDatabase) -> StructKind ``` in the `impl` of `EnumVariant`. There was also a previously existing function `is_unit(self, db: &impl HirDatabase) -> bool` for `EnumVariant` which I removed because it seemed redundant after adding `kind`. Co-authored-by: adamrk <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r--crates/ra_hir_ty/src/lower.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs
index 6a2aded02..c2a3703fa 100644
--- a/crates/ra_hir_ty/src/lower.rs
+++ b/crates/ra_hir_ty/src/lower.rs
@@ -9,6 +9,7 @@ use std::iter;
9use std::sync::Arc; 9use std::sync::Arc;
10 10
11use hir_def::{ 11use hir_def::{
12 adt::StructKind,
12 builtin_type::BuiltinType, 13 builtin_type::BuiltinType,
13 generics::{TypeParamProvenance, WherePredicate, WherePredicateTarget}, 14 generics::{TypeParamProvenance, WherePredicate, WherePredicateTarget},
14 path::{GenericArg, Path, PathSegment, PathSegments}, 15 path::{GenericArg, Path, PathSegment, PathSegments},
@@ -805,8 +806,8 @@ fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFn
805/// Build the type of a tuple struct constructor. 806/// Build the type of a tuple struct constructor.
806fn type_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> Binders<Ty> { 807fn type_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> Binders<Ty> {
807 let struct_data = db.struct_data(def.into()); 808 let struct_data = db.struct_data(def.into());
808 if struct_data.variant_data.is_unit() { 809 if let StructKind::Unit = struct_data.variant_data.kind() {
809 return type_for_adt(db, def.into()); // Unit struct 810 return type_for_adt(db, def.into());
810 } 811 }
811 let generics = generics(db, def.into()); 812 let generics = generics(db, def.into());
812 let substs = Substs::bound_vars(&generics); 813 let substs = Substs::bound_vars(&generics);
@@ -830,8 +831,8 @@ fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId
830fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId) -> Binders<Ty> { 831fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId) -> Binders<Ty> {
831 let enum_data = db.enum_data(def.parent); 832 let enum_data = db.enum_data(def.parent);
832 let var_data = &enum_data.variants[def.local_id].variant_data; 833 let var_data = &enum_data.variants[def.local_id].variant_data;
833 if var_data.is_unit() { 834 if let StructKind::Unit = var_data.kind() {
834 return type_for_adt(db, def.parent.into()); // Unit variant 835 return type_for_adt(db, def.parent.into());
835 } 836 }
836 let generics = generics(db, def.parent.into()); 837 let generics = generics(db, def.parent.into());
837 let substs = Substs::bound_vars(&generics); 838 let substs = Substs::bound_vars(&generics);