From 1d14fd17372b42c3343daf6adc9a520fdf5e9810 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 27 Nov 2019 23:22:20 +0300 Subject: Use Name::missing consistently --- crates/ra_hir_def/src/adt.rs | 18 +++++++++--------- crates/ra_hir_def/src/data.rs | 11 ++++++----- crates/ra_hir_def/src/nameres/collector.rs | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) (limited to 'crates/ra_hir_def') 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::{ /// Note that we use `StructData` for unions as well! #[derive(Debug, Clone, PartialEq, Eq)] pub struct StructData { - pub name: Option, + pub name: Name, pub variant_data: Arc, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct EnumData { - pub name: Option, + pub name: Name, pub variants: Arena, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct EnumVariantData { - pub name: Option, + pub name: Name, pub variant_data: Arc, } @@ -51,14 +51,14 @@ pub struct StructFieldData { impl StructData { pub(crate) fn struct_data_query(db: &impl DefDatabase, id: StructId) -> Arc { let src = id.source(db); - let name = src.value.name().map(|n| n.as_name()); + let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); let variant_data = VariantData::new(src.value.kind()); let variant_data = Arc::new(variant_data); Arc::new(StructData { name, variant_data }) } pub(crate) fn union_data_query(db: &impl DefDatabase, id: UnionId) -> Arc { let src = id.source(db); - let name = src.value.name().map(|n| n.as_name()); + let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); let variant_data = VariantData::new( src.value .record_field_def_list() @@ -73,14 +73,14 @@ impl StructData { impl EnumData { pub(crate) fn enum_data_query(db: &impl DefDatabase, e: EnumId) -> Arc { let src = e.source(db); - let name = src.value.name().map(|n| n.as_name()); + let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); let mut trace = Trace::new_for_arena(); lower_enum(&mut trace, &src.value); Arc::new(EnumData { name, variants: trace.into_arena() }) } - pub(crate) fn variant(&self, name: &Name) -> Option { - let (id, _) = self.variants.iter().find(|(_id, data)| data.name.as_ref() == Some(name))?; + pub fn variant(&self, name: &Name) -> Option { + let (id, _) = self.variants.iter().find(|(_id, data)| &data.name == name)?; Some(id) } } @@ -104,7 +104,7 @@ fn lower_enum( trace.alloc( || var.clone(), || EnumVariantData { - name: var.name().map(|it| it.as_name()), + name: var.name().map_or_else(Name::missing, |it| it.as_name()), variant_data: Arc::new(VariantData::new(var.kind())), }, ); 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 { #[derive(Debug, Clone, PartialEq, Eq)] pub struct TraitData { - pub name: Option, + pub name: Name, pub items: Vec<(Name, AssocItemId)>, pub auto: bool, } @@ -94,7 +94,7 @@ pub struct TraitData { impl TraitData { pub(crate) fn trait_data_query(db: &impl DefDatabase, tr: TraitId) -> Arc { let src = tr.source(db); - let name = src.value.name().map(|n| n.as_name()); + let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); let auto = src.value.is_auto(); let ast_id_map = db.ast_id_map(src.file_id); @@ -104,7 +104,7 @@ impl TraitData { .impl_items() .map(|item_node| match item_node { ast::ImplItem::FnDef(it) => { - let name = it.name().map(|it| it.as_name()).unwrap_or_else(Name::missing); + let name = it.name().map_or_else(Name::missing, |it| it.as_name()); let def = FunctionLoc { container, ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), @@ -114,7 +114,7 @@ impl TraitData { (name, def) } ast::ImplItem::ConstDef(it) => { - let name = it.name().map(|it| it.as_name()).unwrap_or_else(Name::missing); + let name = it.name().map_or_else(Name::missing, |it| it.as_name()); let def = ConstLoc { container, ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), @@ -124,7 +124,7 @@ impl TraitData { (name, def) } ast::ImplItem::TypeAliasDef(it) => { - let name = it.name().map(|it| it.as_name()).unwrap_or_else(Name::missing); + let name = it.name().map_or_else(Name::missing, |it| it.as_name()); let def = TypeAliasLoc { container, ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), @@ -214,6 +214,7 @@ impl ImplData { #[derive(Debug, Clone, PartialEq, Eq)] pub struct ConstData { + /// const _: () = (); pub name: Option, pub type_ref: TypeRef, } 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 .variants .iter() .filter_map(|(local_id, variant_data)| { - let name = variant_data.name.clone()?; + let name = variant_data.name.clone(); let variant = EnumVariantId { parent: e, local_id }; let res = Resolution { def: PerNs::both(variant.into(), variant.into()), -- cgit v1.2.3