diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 17 | ||||
-rw-r--r-- | crates/ra_hir_def/src/adt.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/lib.rs | 25 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide/src/display/function_signature.rs | 7 |
7 files changed, 33 insertions, 52 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 9488521a9..38d66c2a7 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -330,7 +330,7 @@ impl Struct { | |||
330 | Some(self.module(db).krate()) | 330 | Some(self.module(db).krate()) |
331 | } | 331 | } |
332 | 332 | ||
333 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { | 333 | pub fn name(self, db: &impl DefDatabase) -> Name { |
334 | db.struct_data(self.id.into()).name.clone() | 334 | db.struct_data(self.id.into()).name.clone() |
335 | } | 335 | } |
336 | 336 | ||
@@ -371,7 +371,7 @@ pub struct Union { | |||
371 | } | 371 | } |
372 | 372 | ||
373 | impl Union { | 373 | impl Union { |
374 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { | 374 | pub fn name(self, db: &impl DefDatabase) -> Name { |
375 | db.union_data(self.id).name.clone() | 375 | db.union_data(self.id).name.clone() |
376 | } | 376 | } |
377 | 377 | ||
@@ -420,7 +420,7 @@ impl Enum { | |||
420 | Some(self.module(db).krate()) | 420 | Some(self.module(db).krate()) |
421 | } | 421 | } |
422 | 422 | ||
423 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { | 423 | pub fn name(self, db: &impl DefDatabase) -> Name { |
424 | db.enum_data(self.id).name.clone() | 424 | db.enum_data(self.id).name.clone() |
425 | } | 425 | } |
426 | 426 | ||
@@ -433,11 +433,8 @@ impl Enum { | |||
433 | } | 433 | } |
434 | 434 | ||
435 | pub fn variant(self, db: &impl DefDatabase, name: &Name) -> Option<EnumVariant> { | 435 | pub fn variant(self, db: &impl DefDatabase, name: &Name) -> Option<EnumVariant> { |
436 | db.enum_data(self.id) | 436 | let id = db.enum_data(self.id).variant(name)?; |
437 | .variants | 437 | Some(EnumVariant { parent: self, id }) |
438 | .iter() | ||
439 | .find(|(_id, data)| data.name.as_ref() == Some(name)) | ||
440 | .map(|(id, _)| EnumVariant { parent: self, id }) | ||
441 | } | 438 | } |
442 | 439 | ||
443 | pub fn ty(self, db: &impl HirDatabase) -> Type { | 440 | pub fn ty(self, db: &impl HirDatabase) -> Type { |
@@ -459,7 +456,7 @@ impl EnumVariant { | |||
459 | self.parent | 456 | self.parent |
460 | } | 457 | } |
461 | 458 | ||
462 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { | 459 | pub fn name(self, db: &impl DefDatabase) -> Name { |
463 | db.enum_data(self.parent.id).variants[self.id].name.clone() | 460 | db.enum_data(self.parent.id).variants[self.id].name.clone() |
464 | } | 461 | } |
465 | 462 | ||
@@ -720,7 +717,7 @@ impl Trait { | |||
720 | Module { id: self.id.module(db) } | 717 | Module { id: self.id.module(db) } |
721 | } | 718 | } |
722 | 719 | ||
723 | pub fn name(self, db: &impl DefDatabase) -> Option<Name> { | 720 | pub fn name(self, db: &impl DefDatabase) -> Name { |
724 | db.trait_data(self.id).name.clone() | 721 | db.trait_data(self.id).name.clone() |
725 | } | 722 | } |
726 | 723 | ||
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index 0cf418d30..3666529b0 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs | |||
@@ -18,19 +18,19 @@ use crate::{ | |||
18 | /// Note that we use `StructData` for unions as well! | 18 | /// Note that we use `StructData` for unions as well! |
19 | #[derive(Debug, Clone, PartialEq, Eq)] | 19 | #[derive(Debug, Clone, PartialEq, Eq)] |
20 | pub struct StructData { | 20 | pub struct StructData { |
21 | pub name: Option<Name>, | 21 | pub name: Name, |
22 | pub variant_data: Arc<VariantData>, | 22 | pub variant_data: Arc<VariantData>, |
23 | } | 23 | } |
24 | 24 | ||
25 | #[derive(Debug, Clone, PartialEq, Eq)] | 25 | #[derive(Debug, Clone, PartialEq, Eq)] |
26 | pub struct EnumData { | 26 | pub struct EnumData { |
27 | pub name: Option<Name>, | 27 | pub name: Name, |
28 | pub variants: Arena<LocalEnumVariantId, EnumVariantData>, | 28 | pub variants: Arena<LocalEnumVariantId, EnumVariantData>, |
29 | } | 29 | } |
30 | 30 | ||
31 | #[derive(Debug, Clone, PartialEq, Eq)] | 31 | #[derive(Debug, Clone, PartialEq, Eq)] |
32 | pub struct EnumVariantData { | 32 | pub struct EnumVariantData { |
33 | pub name: Option<Name>, | 33 | pub name: Name, |
34 | pub variant_data: Arc<VariantData>, | 34 | pub variant_data: Arc<VariantData>, |
35 | } | 35 | } |
36 | 36 | ||
@@ -51,14 +51,14 @@ pub struct StructFieldData { | |||
51 | impl StructData { | 51 | impl StructData { |
52 | pub(crate) fn struct_data_query(db: &impl DefDatabase, id: StructId) -> Arc<StructData> { | 52 | pub(crate) fn struct_data_query(db: &impl DefDatabase, id: StructId) -> Arc<StructData> { |
53 | let src = id.source(db); | 53 | let src = id.source(db); |
54 | let name = src.value.name().map(|n| n.as_name()); | 54 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); |
55 | let variant_data = VariantData::new(src.value.kind()); | 55 | let variant_data = VariantData::new(src.value.kind()); |
56 | let variant_data = Arc::new(variant_data); | 56 | let variant_data = Arc::new(variant_data); |
57 | Arc::new(StructData { name, variant_data }) | 57 | Arc::new(StructData { name, variant_data }) |
58 | } | 58 | } |
59 | pub(crate) fn union_data_query(db: &impl DefDatabase, id: UnionId) -> Arc<StructData> { | 59 | pub(crate) fn union_data_query(db: &impl DefDatabase, id: UnionId) -> Arc<StructData> { |
60 | let src = id.source(db); | 60 | let src = id.source(db); |
61 | let name = src.value.name().map(|n| n.as_name()); | 61 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); |
62 | let variant_data = VariantData::new( | 62 | let variant_data = VariantData::new( |
63 | src.value | 63 | src.value |
64 | .record_field_def_list() | 64 | .record_field_def_list() |
@@ -73,14 +73,14 @@ impl StructData { | |||
73 | impl EnumData { | 73 | impl EnumData { |
74 | pub(crate) fn enum_data_query(db: &impl DefDatabase, e: EnumId) -> Arc<EnumData> { | 74 | pub(crate) fn enum_data_query(db: &impl DefDatabase, e: EnumId) -> Arc<EnumData> { |
75 | let src = e.source(db); | 75 | let src = e.source(db); |
76 | let name = src.value.name().map(|n| n.as_name()); | 76 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); |
77 | let mut trace = Trace::new_for_arena(); | 77 | let mut trace = Trace::new_for_arena(); |
78 | lower_enum(&mut trace, &src.value); | 78 | lower_enum(&mut trace, &src.value); |
79 | Arc::new(EnumData { name, variants: trace.into_arena() }) | 79 | Arc::new(EnumData { name, variants: trace.into_arena() }) |
80 | } | 80 | } |
81 | 81 | ||
82 | pub(crate) fn variant(&self, name: &Name) -> Option<LocalEnumVariantId> { | 82 | pub fn variant(&self, name: &Name) -> Option<LocalEnumVariantId> { |
83 | let (id, _) = self.variants.iter().find(|(_id, data)| data.name.as_ref() == Some(name))?; | 83 | let (id, _) = self.variants.iter().find(|(_id, data)| &data.name == name)?; |
84 | Some(id) | 84 | Some(id) |
85 | } | 85 | } |
86 | } | 86 | } |
@@ -104,7 +104,7 @@ fn lower_enum( | |||
104 | trace.alloc( | 104 | trace.alloc( |
105 | || var.clone(), | 105 | || var.clone(), |
106 | || EnumVariantData { | 106 | || EnumVariantData { |
107 | name: var.name().map(|it| it.as_name()), | 107 | name: var.name().map_or_else(Name::missing, |it| it.as_name()), |
108 | variant_data: Arc::new(VariantData::new(var.kind())), | 108 | variant_data: Arc::new(VariantData::new(var.kind())), |
109 | }, | 109 | }, |
110 | ); | 110 | ); |
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 813099a05..fee10b237 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs | |||
@@ -86,7 +86,7 @@ impl TypeAliasData { | |||
86 | 86 | ||
87 | #[derive(Debug, Clone, PartialEq, Eq)] | 87 | #[derive(Debug, Clone, PartialEq, Eq)] |
88 | pub struct TraitData { | 88 | pub struct TraitData { |
89 | pub name: Option<Name>, | 89 | pub name: Name, |
90 | pub items: Vec<(Name, AssocItemId)>, | 90 | pub items: Vec<(Name, AssocItemId)>, |
91 | pub auto: bool, | 91 | pub auto: bool, |
92 | } | 92 | } |
@@ -94,7 +94,7 @@ pub struct TraitData { | |||
94 | impl TraitData { | 94 | impl TraitData { |
95 | pub(crate) fn trait_data_query(db: &impl DefDatabase, tr: TraitId) -> Arc<TraitData> { | 95 | pub(crate) fn trait_data_query(db: &impl DefDatabase, tr: TraitId) -> Arc<TraitData> { |
96 | let src = tr.source(db); | 96 | let src = tr.source(db); |
97 | let name = src.value.name().map(|n| n.as_name()); | 97 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); |
98 | let auto = src.value.is_auto(); | 98 | let auto = src.value.is_auto(); |
99 | let ast_id_map = db.ast_id_map(src.file_id); | 99 | let ast_id_map = db.ast_id_map(src.file_id); |
100 | 100 | ||
@@ -104,7 +104,7 @@ impl TraitData { | |||
104 | .impl_items() | 104 | .impl_items() |
105 | .map(|item_node| match item_node { | 105 | .map(|item_node| match item_node { |
106 | ast::ImplItem::FnDef(it) => { | 106 | ast::ImplItem::FnDef(it) => { |
107 | let name = it.name().map(|it| it.as_name()).unwrap_or_else(Name::missing); | 107 | let name = it.name().map_or_else(Name::missing, |it| it.as_name()); |
108 | let def = FunctionLoc { | 108 | let def = FunctionLoc { |
109 | container, | 109 | container, |
110 | ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), | 110 | ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), |
@@ -114,7 +114,7 @@ impl TraitData { | |||
114 | (name, def) | 114 | (name, def) |
115 | } | 115 | } |
116 | ast::ImplItem::ConstDef(it) => { | 116 | ast::ImplItem::ConstDef(it) => { |
117 | let name = it.name().map(|it| it.as_name()).unwrap_or_else(Name::missing); | 117 | let name = it.name().map_or_else(Name::missing, |it| it.as_name()); |
118 | let def = ConstLoc { | 118 | let def = ConstLoc { |
119 | container, | 119 | container, |
120 | ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), | 120 | ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), |
@@ -124,7 +124,7 @@ impl TraitData { | |||
124 | (name, def) | 124 | (name, def) |
125 | } | 125 | } |
126 | ast::ImplItem::TypeAliasDef(it) => { | 126 | ast::ImplItem::TypeAliasDef(it) => { |
127 | let name = it.name().map(|it| it.as_name()).unwrap_or_else(Name::missing); | 127 | let name = it.name().map_or_else(Name::missing, |it| it.as_name()); |
128 | let def = TypeAliasLoc { | 128 | let def = TypeAliasLoc { |
129 | container, | 129 | container, |
130 | ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), | 130 | ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), |
@@ -214,6 +214,7 @@ impl ImplData { | |||
214 | 214 | ||
215 | #[derive(Debug, Clone, PartialEq, Eq)] | 215 | #[derive(Debug, Clone, PartialEq, Eq)] |
216 | pub struct ConstData { | 216 | pub struct ConstData { |
217 | /// const _: () = (); | ||
217 | pub name: Option<Name>, | 218 | pub name: Option<Name>, |
218 | pub type_ref: TypeRef, | 219 | pub type_ref: TypeRef, |
219 | } | 220 | } |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 603b49738..fd8245113 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -362,7 +362,7 @@ where | |||
362 | .variants | 362 | .variants |
363 | .iter() | 363 | .iter() |
364 | .filter_map(|(local_id, variant_data)| { | 364 | .filter_map(|(local_id, variant_data)| { |
365 | let name = variant_data.name.clone()?; | 365 | let name = variant_data.name.clone(); |
366 | let variant = EnumVariantId { parent: e, local_id }; | 366 | let variant = EnumVariantId { parent: e, local_id }; |
367 | let res = Resolution { | 367 | let res = Resolution { |
368 | def: PerNs::both(variant.into(), variant.into()), | 368 | def: PerNs::both(variant.into(), variant.into()), |
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index c9ee34008..b45c8f82f 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs | |||
@@ -901,12 +901,10 @@ impl HirDisplay for ApplicationTy { | |||
901 | let sig = f.db.callable_item_signature(def); | 901 | let sig = f.db.callable_item_signature(def); |
902 | let name = match def { | 902 | let name = match def { |
903 | CallableDef::FunctionId(ff) => f.db.function_data(ff).name.clone(), | 903 | CallableDef::FunctionId(ff) => f.db.function_data(ff).name.clone(), |
904 | CallableDef::StructId(s) => { | 904 | CallableDef::StructId(s) => f.db.struct_data(s).name.clone(), |
905 | f.db.struct_data(s).name.clone().unwrap_or_else(Name::missing) | ||
906 | } | ||
907 | CallableDef::EnumVariantId(e) => { | 905 | CallableDef::EnumVariantId(e) => { |
908 | let enum_data = f.db.enum_data(e.parent); | 906 | let enum_data = f.db.enum_data(e.parent); |
909 | enum_data.variants[e.local_id].name.clone().unwrap_or_else(Name::missing) | 907 | enum_data.variants[e.local_id].name.clone() |
910 | } | 908 | } |
911 | }; | 909 | }; |
912 | match def { | 910 | match def { |
@@ -929,8 +927,7 @@ impl HirDisplay for ApplicationTy { | |||
929 | AdtId::StructId(it) => f.db.struct_data(it).name.clone(), | 927 | AdtId::StructId(it) => f.db.struct_data(it).name.clone(), |
930 | AdtId::UnionId(it) => f.db.union_data(it).name.clone(), | 928 | AdtId::UnionId(it) => f.db.union_data(it).name.clone(), |
931 | AdtId::EnumId(it) => f.db.enum_data(it).name.clone(), | 929 | AdtId::EnumId(it) => f.db.enum_data(it).name.clone(), |
932 | } | 930 | }; |
933 | .unwrap_or_else(Name::missing); | ||
934 | write!(f, "{}", name)?; | 931 | write!(f, "{}", name)?; |
935 | if self.parameters.len() > 0 { | 932 | if self.parameters.len() > 0 { |
936 | write!(f, "<")?; | 933 | write!(f, "<")?; |
@@ -943,7 +940,7 @@ impl HirDisplay for ApplicationTy { | |||
943 | ContainerId::TraitId(it) => it, | 940 | ContainerId::TraitId(it) => it, |
944 | _ => panic!("not an associated type"), | 941 | _ => panic!("not an associated type"), |
945 | }; | 942 | }; |
946 | let trait_name = f.db.trait_data(trait_).name.clone().unwrap_or_else(Name::missing); | 943 | let trait_name = f.db.trait_data(trait_).name.clone(); |
947 | let name = f.db.type_alias_data(type_alias).name.clone(); | 944 | let name = f.db.type_alias_data(type_alias).name.clone(); |
948 | write!(f, "{}::{}", trait_name, name)?; | 945 | write!(f, "{}::{}", trait_name, name)?; |
949 | if self.parameters.len() > 0 { | 946 | if self.parameters.len() > 0 { |
@@ -971,8 +968,7 @@ impl HirDisplay for ProjectionTy { | |||
971 | return write!(f, "…"); | 968 | return write!(f, "…"); |
972 | } | 969 | } |
973 | 970 | ||
974 | let trait_name = | 971 | let trait_name = f.db.trait_data(self.trait_(f.db)).name.clone(); |
975 | f.db.trait_data(self.trait_(f.db)).name.clone().unwrap_or_else(Name::missing); | ||
976 | write!(f, "<{} as {}", self.parameters[0].display(f.db), trait_name,)?; | 972 | write!(f, "<{} as {}", self.parameters[0].display(f.db), trait_name,)?; |
977 | if self.parameters.len() > 1 { | 973 | if self.parameters.len() > 1 { |
978 | write!(f, "<")?; | 974 | write!(f, "<")?; |
@@ -1021,14 +1017,7 @@ impl HirDisplay for Ty { | |||
1021 | // We assume that the self type is $0 (i.e. the | 1017 | // We assume that the self type is $0 (i.e. the |
1022 | // existential) here, which is the only thing that's | 1018 | // existential) here, which is the only thing that's |
1023 | // possible in actual Rust, and hence don't print it | 1019 | // possible in actual Rust, and hence don't print it |
1024 | write!( | 1020 | write!(f, "{}", f.db.trait_data(trait_ref.trait_).name.clone())?; |
1025 | f, | ||
1026 | "{}", | ||
1027 | f.db.trait_data(trait_ref.trait_) | ||
1028 | .name | ||
1029 | .clone() | ||
1030 | .unwrap_or_else(Name::missing) | ||
1031 | )?; | ||
1032 | if trait_ref.substs.len() > 1 { | 1021 | if trait_ref.substs.len() > 1 { |
1033 | write!(f, "<")?; | 1022 | write!(f, "<")?; |
1034 | f.write_joined(&trait_ref.substs[1..], ", ")?; | 1023 | f.write_joined(&trait_ref.substs[1..], ", ")?; |
@@ -1088,7 +1077,7 @@ impl TraitRef { | |||
1088 | } else { | 1077 | } else { |
1089 | write!(f, ": ")?; | 1078 | write!(f, ": ")?; |
1090 | } | 1079 | } |
1091 | write!(f, "{}", f.db.trait_data(self.trait_).name.clone().unwrap_or_else(Name::missing))?; | 1080 | write!(f, "{}", f.db.trait_data(self.trait_).name.clone())?; |
1092 | if self.substs.len() > 1 { | 1081 | if self.substs.len() > 1 { |
1093 | write!(f, "<")?; | 1082 | write!(f, "<")?; |
1094 | f.write_joined(&self.substs[1..], ", ")?; | 1083 | f.write_joined(&self.substs[1..], ", ")?; |
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 5f056730a..97475fc0b 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -267,10 +267,7 @@ impl Completions { | |||
267 | 267 | ||
268 | pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) { | 268 | pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) { |
269 | let is_deprecated = is_deprecated(variant, ctx.db); | 269 | let is_deprecated = is_deprecated(variant, ctx.db); |
270 | let name = match variant.name(ctx.db) { | 270 | let name = variant.name(ctx.db); |
271 | Some(it) => it, | ||
272 | None => return, | ||
273 | }; | ||
274 | let detail_types = variant.fields(ctx.db).into_iter().map(|field| field.ty(ctx.db)); | 271 | let detail_types = variant.fields(ctx.db).into_iter().map(|field| field.ty(ctx.db)); |
275 | let detail = join(detail_types.map(|t| t.display(ctx.db).to_string())) | 272 | let detail = join(detail_types.map(|t| t.display(ctx.db).to_string())) |
276 | .separator(", ") | 273 | .separator(", ") |
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index d96de4e4c..324ad9552 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs | |||
@@ -93,12 +93,9 @@ impl FunctionSignature { | |||
93 | _ => (), | 93 | _ => (), |
94 | }; | 94 | }; |
95 | 95 | ||
96 | let parent_name = match variant.parent_enum(db).name(db) { | 96 | let parent_name = variant.parent_enum(db).name(db).to_string(); |
97 | Some(name) => name.to_string(), | ||
98 | None => "missing".into(), | ||
99 | }; | ||
100 | 97 | ||
101 | let name = format!("{}::{}", parent_name, variant.name(db).unwrap()); | 98 | let name = format!("{}::{}", parent_name, variant.name(db)); |
102 | 99 | ||
103 | let params = variant | 100 | let params = variant |
104 | .fields(db) | 101 | .fields(db) |