aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-27 20:27:01 +0000
committerGitHub <[email protected]>2019-11-27 20:27:01 +0000
commit922ec610d19aef7fb8b4df389ac318f4f2a0202c (patch)
treef94102d2fd9431abaa5447315f152838db5bf9fc /crates/ra_hir_def/src
parentc0bb667a7dfaecfefacf0b3b6cb1e483aac6747a (diff)
parent1d14fd17372b42c3343daf6adc9a520fdf5e9810 (diff)
Merge #2433
2433: Use Name::missing consistently r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/adt.rs18
-rw-r--r--crates/ra_hir_def/src/data.rs11
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs2
3 files changed, 16 insertions, 15 deletions
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)]
20pub struct StructData { 20pub 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)]
26pub struct EnumData { 26pub 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)]
32pub struct EnumVariantData { 32pub 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 {
51impl StructData { 51impl 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 {
73impl EnumData { 73impl 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)]
88pub struct TraitData { 88pub 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 {
94impl TraitData { 94impl 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)]
216pub struct ConstData { 216pub 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()),