Use Name::missing consistently
This commit is contained in:
parent
c0bb667a7d
commit
1d14fd1737
7 changed files with 33 additions and 52 deletions
|
@ -330,7 +330,7 @@ impl Struct {
|
|||
Some(self.module(db).krate())
|
||||
}
|
||||
|
||||
pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
|
||||
pub fn name(self, db: &impl DefDatabase) -> Name {
|
||||
db.struct_data(self.id.into()).name.clone()
|
||||
}
|
||||
|
||||
|
@ -371,7 +371,7 @@ pub struct Union {
|
|||
}
|
||||
|
||||
impl Union {
|
||||
pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
|
||||
pub fn name(self, db: &impl DefDatabase) -> Name {
|
||||
db.union_data(self.id).name.clone()
|
||||
}
|
||||
|
||||
|
@ -420,7 +420,7 @@ impl Enum {
|
|||
Some(self.module(db).krate())
|
||||
}
|
||||
|
||||
pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
|
||||
pub fn name(self, db: &impl DefDatabase) -> Name {
|
||||
db.enum_data(self.id).name.clone()
|
||||
}
|
||||
|
||||
|
@ -433,11 +433,8 @@ impl Enum {
|
|||
}
|
||||
|
||||
pub fn variant(self, db: &impl DefDatabase, name: &Name) -> Option<EnumVariant> {
|
||||
db.enum_data(self.id)
|
||||
.variants
|
||||
.iter()
|
||||
.find(|(_id, data)| data.name.as_ref() == Some(name))
|
||||
.map(|(id, _)| EnumVariant { parent: self, id })
|
||||
let id = db.enum_data(self.id).variant(name)?;
|
||||
Some(EnumVariant { parent: self, id })
|
||||
}
|
||||
|
||||
pub fn ty(self, db: &impl HirDatabase) -> Type {
|
||||
|
@ -459,7 +456,7 @@ impl EnumVariant {
|
|||
self.parent
|
||||
}
|
||||
|
||||
pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
|
||||
pub fn name(self, db: &impl DefDatabase) -> Name {
|
||||
db.enum_data(self.parent.id).variants[self.id].name.clone()
|
||||
}
|
||||
|
||||
|
@ -720,7 +717,7 @@ impl Trait {
|
|||
Module { id: self.id.module(db) }
|
||||
}
|
||||
|
||||
pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
|
||||
pub fn name(self, db: &impl DefDatabase) -> Name {
|
||||
db.trait_data(self.id).name.clone()
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Name>,
|
||||
pub name: Name,
|
||||
pub variant_data: Arc<VariantData>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct EnumData {
|
||||
pub name: Option<Name>,
|
||||
pub name: Name,
|
||||
pub variants: Arena<LocalEnumVariantId, EnumVariantData>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct EnumVariantData {
|
||||
pub name: Option<Name>,
|
||||
pub name: Name,
|
||||
pub variant_data: Arc<VariantData>,
|
||||
}
|
||||
|
||||
|
@ -51,14 +51,14 @@ pub struct StructFieldData {
|
|||
impl StructData {
|
||||
pub(crate) fn struct_data_query(db: &impl DefDatabase, id: StructId) -> Arc<StructData> {
|
||||
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<StructData> {
|
||||
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<EnumData> {
|
||||
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<LocalEnumVariantId> {
|
||||
let (id, _) = self.variants.iter().find(|(_id, data)| data.name.as_ref() == Some(name))?;
|
||||
pub fn variant(&self, name: &Name) -> Option<LocalEnumVariantId> {
|
||||
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())),
|
||||
},
|
||||
);
|
||||
|
|
|
@ -86,7 +86,7 @@ impl TypeAliasData {
|
|||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct TraitData {
|
||||
pub name: Option<Name>,
|
||||
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<TraitData> {
|
||||
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<Name>,
|
||||
pub type_ref: TypeRef,
|
||||
}
|
||||
|
|
|
@ -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()),
|
||||
|
|
|
@ -901,12 +901,10 @@ impl HirDisplay for ApplicationTy {
|
|||
let sig = f.db.callable_item_signature(def);
|
||||
let name = match def {
|
||||
CallableDef::FunctionId(ff) => f.db.function_data(ff).name.clone(),
|
||||
CallableDef::StructId(s) => {
|
||||
f.db.struct_data(s).name.clone().unwrap_or_else(Name::missing)
|
||||
}
|
||||
CallableDef::StructId(s) => f.db.struct_data(s).name.clone(),
|
||||
CallableDef::EnumVariantId(e) => {
|
||||
let enum_data = f.db.enum_data(e.parent);
|
||||
enum_data.variants[e.local_id].name.clone().unwrap_or_else(Name::missing)
|
||||
enum_data.variants[e.local_id].name.clone()
|
||||
}
|
||||
};
|
||||
match def {
|
||||
|
@ -929,8 +927,7 @@ impl HirDisplay for ApplicationTy {
|
|||
AdtId::StructId(it) => f.db.struct_data(it).name.clone(),
|
||||
AdtId::UnionId(it) => f.db.union_data(it).name.clone(),
|
||||
AdtId::EnumId(it) => f.db.enum_data(it).name.clone(),
|
||||
}
|
||||
.unwrap_or_else(Name::missing);
|
||||
};
|
||||
write!(f, "{}", name)?;
|
||||
if self.parameters.len() > 0 {
|
||||
write!(f, "<")?;
|
||||
|
@ -943,7 +940,7 @@ impl HirDisplay for ApplicationTy {
|
|||
ContainerId::TraitId(it) => it,
|
||||
_ => panic!("not an associated type"),
|
||||
};
|
||||
let trait_name = f.db.trait_data(trait_).name.clone().unwrap_or_else(Name::missing);
|
||||
let trait_name = f.db.trait_data(trait_).name.clone();
|
||||
let name = f.db.type_alias_data(type_alias).name.clone();
|
||||
write!(f, "{}::{}", trait_name, name)?;
|
||||
if self.parameters.len() > 0 {
|
||||
|
@ -971,8 +968,7 @@ impl HirDisplay for ProjectionTy {
|
|||
return write!(f, "…");
|
||||
}
|
||||
|
||||
let trait_name =
|
||||
f.db.trait_data(self.trait_(f.db)).name.clone().unwrap_or_else(Name::missing);
|
||||
let trait_name = f.db.trait_data(self.trait_(f.db)).name.clone();
|
||||
write!(f, "<{} as {}", self.parameters[0].display(f.db), trait_name,)?;
|
||||
if self.parameters.len() > 1 {
|
||||
write!(f, "<")?;
|
||||
|
@ -1021,14 +1017,7 @@ impl HirDisplay for Ty {
|
|||
// We assume that the self type is $0 (i.e. the
|
||||
// existential) here, which is the only thing that's
|
||||
// possible in actual Rust, and hence don't print it
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
f.db.trait_data(trait_ref.trait_)
|
||||
.name
|
||||
.clone()
|
||||
.unwrap_or_else(Name::missing)
|
||||
)?;
|
||||
write!(f, "{}", f.db.trait_data(trait_ref.trait_).name.clone())?;
|
||||
if trait_ref.substs.len() > 1 {
|
||||
write!(f, "<")?;
|
||||
f.write_joined(&trait_ref.substs[1..], ", ")?;
|
||||
|
@ -1088,7 +1077,7 @@ impl TraitRef {
|
|||
} else {
|
||||
write!(f, ": ")?;
|
||||
}
|
||||
write!(f, "{}", f.db.trait_data(self.trait_).name.clone().unwrap_or_else(Name::missing))?;
|
||||
write!(f, "{}", f.db.trait_data(self.trait_).name.clone())?;
|
||||
if self.substs.len() > 1 {
|
||||
write!(f, "<")?;
|
||||
f.write_joined(&self.substs[1..], ", ")?;
|
||||
|
|
|
@ -267,10 +267,7 @@ impl Completions {
|
|||
|
||||
pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) {
|
||||
let is_deprecated = is_deprecated(variant, ctx.db);
|
||||
let name = match variant.name(ctx.db) {
|
||||
Some(it) => it,
|
||||
None => return,
|
||||
};
|
||||
let name = variant.name(ctx.db);
|
||||
let detail_types = variant.fields(ctx.db).into_iter().map(|field| field.ty(ctx.db));
|
||||
let detail = join(detail_types.map(|t| t.display(ctx.db).to_string()))
|
||||
.separator(", ")
|
||||
|
|
|
@ -93,12 +93,9 @@ impl FunctionSignature {
|
|||
_ => (),
|
||||
};
|
||||
|
||||
let parent_name = match variant.parent_enum(db).name(db) {
|
||||
Some(name) => name.to_string(),
|
||||
None => "missing".into(),
|
||||
};
|
||||
let parent_name = variant.parent_enum(db).name(db).to_string();
|
||||
|
||||
let name = format!("{}::{}", parent_name, variant.name(db).unwrap());
|
||||
let name = format!("{}::{}", parent_name, variant.name(db));
|
||||
|
||||
let params = variant
|
||||
.fields(db)
|
||||
|
|
Loading…
Add table
Reference in a new issue