make various enums "inherit" from AdtDef

This commit is contained in:
Aleksey Kladov 2019-09-13 00:10:16 +03:00
parent d8b621cf26
commit 45117c6388
17 changed files with 156 additions and 121 deletions

View file

@ -9,29 +9,9 @@ use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner};
use crate::{
db::{AstDatabase, DefDatabase, HirDatabase},
type_ref::TypeRef,
AsName, Crate, Enum, EnumVariant, FieldSource, HasSource, Name, Source, Struct, StructField,
Union,
AsName, Enum, EnumVariant, FieldSource, HasSource, Name, Source, Struct, StructField,
};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum AdtDef {
Struct(Struct),
Union(Union),
Enum(Enum),
}
impl_froms!(AdtDef: Struct, Union, Enum);
impl AdtDef {
pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> {
match self {
AdtDef::Struct(s) => s.module(db),
AdtDef::Union(s) => s.module(db),
AdtDef::Enum(e) => e.module(db),
}
.krate(db)
}
}
impl Struct {
pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
db.struct_data(self).variant_data.clone()

View file

@ -127,9 +127,7 @@ impl BuiltinType {
pub enum ModuleDef {
Module(Module),
Function(Function),
Struct(Struct),
Union(Union),
Enum(Enum),
AdtDef(AdtDef),
// Can't be directly declared, but can be imported.
EnumVariant(EnumVariant),
Const(Const),
@ -141,9 +139,7 @@ pub enum ModuleDef {
impl_froms!(
ModuleDef: Module,
Function,
Struct,
Union,
Enum,
AdtDef,
EnumVariant,
Const,
Static,
@ -152,6 +148,24 @@ impl_froms!(
BuiltinType
);
impl From<Struct> for ModuleDef {
fn from(it: Struct) -> ModuleDef {
ModuleDef::AdtDef(AdtDef::Struct(it))
}
}
impl From<Enum> for ModuleDef {
fn from(it: Enum) -> ModuleDef {
ModuleDef::AdtDef(AdtDef::Enum(it))
}
}
impl From<Union> for ModuleDef {
fn from(it: Union) -> ModuleDef {
ModuleDef::AdtDef(AdtDef::Union(it))
}
}
pub enum ModuleSource {
SourceFile(ast::SourceFile),
Module(ast::Module),
@ -500,6 +514,41 @@ impl EnumVariant {
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum AdtDef {
Struct(Struct),
Union(Union),
Enum(Enum),
}
impl_froms!(AdtDef: Struct, Union, Enum);
impl AdtDef {
pub fn ty(self, db: &impl HirDatabase) -> Ty {
match self {
AdtDef::Struct(it) => it.ty(db),
AdtDef::Union(it) => it.ty(db),
AdtDef::Enum(it) => it.ty(db),
}
}
pub(crate) fn krate(self, db: &impl HirDatabase) -> Option<Crate> {
match self {
AdtDef::Struct(s) => s.module(db),
AdtDef::Union(s) => s.module(db),
AdtDef::Enum(e) => e.module(db),
}
.krate(db)
}
pub(crate) fn resolver(self, db: &impl HirDatabase) -> Resolver {
match self {
AdtDef::Struct(it) => it.resolver(db),
AdtDef::Union(it) => it.resolver(db),
AdtDef::Enum(it) => it.resolver(db),
}
}
}
/// The defs which have a body.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum DefWithBody {

View file

@ -4,14 +4,13 @@ use ra_syntax::ast;
use rustc_hash::FxHashSet;
use crate::{
adt::AdtDef,
db::HirDatabase,
diagnostics::{DiagnosticSink, MissingFields, MissingOkInTailExpr},
expr::AstPtr,
name,
path::{PathKind, PathSegment},
ty::{ApplicationTy, InferenceResult, Ty, TypeCtor},
Function, Name, Path,
AdtDef, Function, Name, Path,
};
use super::{Expr, ExprId, RecordLitField};

View file

@ -47,9 +47,7 @@ pub struct WherePredicate {
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
pub enum GenericDef {
Function(Function),
Struct(Struct),
Union(Union),
Enum(Enum),
AdtDef(AdtDef),
Trait(Trait),
TypeAlias(TypeAlias),
ImplBlock(ImplBlock),
@ -57,7 +55,25 @@ pub enum GenericDef {
// can, and this makes some code easier to write
EnumVariant(EnumVariant),
}
impl_froms!(GenericDef: Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock, EnumVariant);
impl_froms!(GenericDef: Function, AdtDef, Trait, TypeAlias, ImplBlock, EnumVariant);
impl From<Struct> for GenericDef {
fn from(it: Struct) -> GenericDef {
GenericDef::AdtDef(AdtDef::Struct(it))
}
}
impl From<Enum> for GenericDef {
fn from(it: Enum) -> GenericDef {
GenericDef::AdtDef(AdtDef::Enum(it))
}
}
impl From<Union> for GenericDef {
fn from(it: Union) -> GenericDef {
GenericDef::AdtDef(AdtDef::Union(it))
}
}
impl GenericParams {
pub(crate) fn generic_params_query(
@ -69,10 +85,7 @@ impl GenericParams {
GenericDef::Function(it) => it.container(db).map(GenericDef::from),
GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from),
GenericDef::EnumVariant(it) => Some(it.parent_enum(db).into()),
GenericDef::Struct(_)
| GenericDef::Union(_)
| GenericDef::Enum(_)
| GenericDef::Trait(_) => None,
GenericDef::AdtDef(_) | GenericDef::Trait(_) => None,
GenericDef::ImplBlock(_) => None,
};
generics.parent_params = parent.map(|p| db.generic_params(p));
@ -80,9 +93,9 @@ impl GenericParams {
// FIXME: add `: Sized` bound for everything except for `Self` in traits
match def {
GenericDef::Function(it) => generics.fill(&it.source(db).ast, start),
GenericDef::Struct(it) => generics.fill(&it.source(db).ast, start),
GenericDef::Union(it) => generics.fill(&it.source(db).ast, start),
GenericDef::Enum(it) => generics.fill(&it.source(db).ast, start),
GenericDef::AdtDef(AdtDef::Struct(it)) => generics.fill(&it.source(db).ast, start),
GenericDef::AdtDef(AdtDef::Union(it)) => generics.fill(&it.source(db).ast, start),
GenericDef::AdtDef(AdtDef::Enum(it)) => generics.fill(&it.source(db).ast, start),
GenericDef::Trait(it) => {
// traits get the Self type as an implicit first type parameter
generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None });
@ -186,9 +199,7 @@ impl GenericDef {
pub(crate) fn resolver(&self, db: &impl HirDatabase) -> crate::Resolver {
match self {
GenericDef::Function(inner) => inner.resolver(db),
GenericDef::Struct(inner) => inner.resolver(db),
GenericDef::Union(inner) => inner.resolver(db),
GenericDef::Enum(inner) => inner.resolver(db),
GenericDef::AdtDef(adt) => adt.resolver(db),
GenericDef::Trait(inner) => inner.resolver(db),
GenericDef::TypeAlias(inner) => inner.resolver(db),
GenericDef::ImplBlock(inner) => inner.resolver(db),
@ -206,16 +217,6 @@ impl From<Container> for GenericDef {
}
}
impl From<crate::adt::AdtDef> for GenericDef {
fn from(adt: crate::adt::AdtDef) -> Self {
match adt {
AdtDef::Struct(s) => s.into(),
AdtDef::Union(u) => u.into(),
AdtDef::Enum(e) => e.into(),
}
}
}
pub trait HasGenericParams: Copy {
fn generic_params(self, db: &impl DefDatabase) -> Arc<GenericParams>;
}

View file

@ -5,7 +5,7 @@ use ra_syntax::{ast::AttrsOwner, SmolStr};
use crate::{
db::{AstDatabase, DefDatabase, HirDatabase},
Crate, Enum, Function, HasSource, ImplBlock, Module, ModuleDef, Static, Struct, Trait,
AdtDef, Crate, Enum, Function, HasSource, ImplBlock, Module, ModuleDef, Static, Struct, Trait,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@ -107,8 +107,12 @@ impl LangItems {
ModuleDef::Trait(trait_) => {
self.collect_lang_item(db, trait_, LangItemTarget::Trait)
}
ModuleDef::Enum(e) => self.collect_lang_item(db, e, LangItemTarget::Enum),
ModuleDef::Struct(s) => self.collect_lang_item(db, s, LangItemTarget::Struct),
ModuleDef::AdtDef(AdtDef::Enum(e)) => {
self.collect_lang_item(db, e, LangItemTarget::Enum)
}
ModuleDef::AdtDef(AdtDef::Struct(s)) => {
self.collect_lang_item(db, s, LangItemTarget::Struct)
}
ModuleDef::Function(f) => self.collect_lang_item(db, f, LangItemTarget::Function),
ModuleDef::Static(s) => self.collect_lang_item(db, s, LangItemTarget::Static),
_ => {}

View file

@ -57,7 +57,7 @@ use crate::{
};
pub use self::{
adt::{AdtDef, VariantDef},
adt::VariantDef,
either::Either,
expr::ExprScopes,
generics::{GenericParam, GenericParams, HasGenericParams},
@ -78,7 +78,7 @@ pub use self::{
pub use self::code_model::{
docs::{DocDef, Docs, Documentation},
src::{HasBodySource, HasSource, Source},
BuiltinType, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
AdtDef, BuiltinType, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, ModuleSource,
Static, Struct, StructField, Trait, TypeAlias, Union,
};

View file

@ -69,7 +69,8 @@ use crate::{
diagnostics::DiagnosticSink,
ids::MacroDefId,
nameres::diagnostics::DefDiagnostic,
AstId, BuiltinType, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, Trait,
AdtDef, AstId, BuiltinType, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path,
PathKind, Trait,
};
pub(crate) use self::raw::{ImportSourceMap, RawItems};
@ -425,7 +426,7 @@ impl CrateDefMap {
}
}
}
ModuleDef::Enum(e) => {
ModuleDef::AdtDef(AdtDef::Enum(e)) => {
// enum variant
tested_by!(can_import_enum_variant);
match e.variant(db, &segment.name) {

View file

@ -13,8 +13,8 @@ use crate::{
raw, Crate, CrateDefMap, CrateModuleId, ModuleData, ModuleDef, PerNs, ReachedFixedPoint,
Resolution, ResolveMode,
},
AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, Static,
Struct, Trait, TypeAlias, Union,
AdtDef, AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind,
Static, Struct, Trait, TypeAlias, Union,
};
pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
@ -314,7 +314,7 @@ where
.push((module_id, import_id));
}
}
Some(ModuleDef::Enum(e)) => {
Some(ModuleDef::AdtDef(AdtDef::Enum(e))) => {
tested_by!(glob_enum);
// glob import from enum => just import all the variants
let variants = e.variants(self.db);

View file

@ -15,7 +15,7 @@ use crate::{
name::{Name, SELF_PARAM, SELF_TYPE},
nameres::{CrateDefMap, CrateModuleId, PerNs},
path::Path,
Enum, MacroDef, ModuleDef, Struct, Trait,
AdtDef, Enum, MacroDef, ModuleDef, Struct, Trait,
};
#[derive(Debug, Clone, Default)]
@ -143,7 +143,7 @@ impl Resolver {
) -> Option<Struct> {
let res = self.resolve_path_segments(db, path).into_fully_resolved().take_types()?;
match res {
Resolution::Def(ModuleDef::Struct(it)) => Some(it),
Resolution::Def(ModuleDef::AdtDef(AdtDef::Struct(it))) => Some(it),
_ => None,
}
}
@ -152,7 +152,7 @@ impl Resolver {
pub(crate) fn resolve_known_enum(&self, db: &impl HirDatabase, path: &Path) -> Option<Enum> {
let res = self.resolve_path_segments(db, path).into_fully_resolved().take_types()?;
match res {
Resolution::Def(ModuleDef::Enum(it)) => Some(it),
Resolution::Def(ModuleDef::AdtDef(AdtDef::Enum(it))) => Some(it),
_ => None,
}
}

View file

@ -668,7 +668,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
// FIXME remove the duplication between here and `Ty::from_path`?
let substs = Ty::substs_from_path(self.db, resolver, path, def);
match def {
TypableDef::Struct(s) => {
TypableDef::AdtDef(AdtDef::Struct(s)) => {
let ty = s.ty(self.db);
let ty = self.insert_type_vars(ty.apply_substs(substs));
(ty, Some(s.into()))
@ -678,10 +678,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
let ty = self.insert_type_vars(ty.apply_substs(substs));
(ty, Some(var.into()))
}
TypableDef::Union(_)
TypableDef::AdtDef(AdtDef::Enum(_))
| TypableDef::AdtDef(AdtDef::Union(_))
| TypableDef::TypeAlias(_)
| TypableDef::Function(_)
| TypableDef::Enum(_)
| TypableDef::Const(_)
| TypableDef::Static(_)
| TypableDef::BuiltinType(_) => (Ty::Unknown, None),

View file

@ -172,9 +172,7 @@ impl Ty {
) -> Substs {
let def_generic: Option<GenericDef> = match resolved {
TypableDef::Function(func) => Some(func.into()),
TypableDef::Struct(s) => Some(s.into()),
TypableDef::Union(u) => Some(u.into()),
TypableDef::Enum(e) => Some(e.into()),
TypableDef::AdtDef(adt) => Some(adt.into()),
TypableDef::EnumVariant(var) => Some(var.parent_enum(db).into()),
TypableDef::TypeAlias(t) => Some(t.into()),
TypableDef::Const(_) | TypableDef::Static(_) | TypableDef::BuiltinType(_) => None,
@ -193,9 +191,7 @@ impl Ty {
let last = path.segments.last().expect("path should have at least one segment");
let segment = match resolved {
TypableDef::Function(_)
| TypableDef::Struct(_)
| TypableDef::Union(_)
| TypableDef::Enum(_)
| TypableDef::AdtDef(_)
| TypableDef::Const(_)
| TypableDef::Static(_)
| TypableDef::TypeAlias(_)
@ -410,11 +406,11 @@ fn assoc_type_bindings_from_type_bound<'a>(
pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace) -> Ty {
match (def, ns) {
(TypableDef::Function(f), Namespace::Values) => type_for_fn(db, f),
(TypableDef::Struct(s), Namespace::Types) => type_for_adt(db, s),
(TypableDef::Struct(s), Namespace::Values) => type_for_struct_constructor(db, s),
(TypableDef::Enum(e), Namespace::Types) => type_for_adt(db, e),
(TypableDef::AdtDef(AdtDef::Struct(s)), Namespace::Values) => {
type_for_struct_constructor(db, s)
}
(TypableDef::AdtDef(adt), Namespace::Types) => type_for_adt(db, adt),
(TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v),
(TypableDef::Union(u), Namespace::Types) => type_for_adt(db, u),
(TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t),
(TypableDef::Const(c), Namespace::Values) => type_for_const(db, c),
(TypableDef::Static(c), Namespace::Values) => type_for_static(db, c),
@ -422,8 +418,8 @@ pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace
// 'error' cases:
(TypableDef::Function(_), Namespace::Types) => Ty::Unknown,
(TypableDef::Union(_), Namespace::Values) => Ty::Unknown,
(TypableDef::Enum(_), Namespace::Values) => Ty::Unknown,
(TypableDef::AdtDef(AdtDef::Union(_)), Namespace::Values) => Ty::Unknown,
(TypableDef::AdtDef(AdtDef::Enum(_)), Namespace::Values) => Ty::Unknown,
(TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown,
(TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown,
(TypableDef::Const(_), Namespace::Types) => Ty::Unknown,
@ -608,34 +604,38 @@ fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum TypableDef {
Function(Function),
Struct(Struct),
Union(Union),
Enum(Enum),
AdtDef(AdtDef),
EnumVariant(EnumVariant),
TypeAlias(TypeAlias),
Const(Const),
Static(Static),
BuiltinType(BuiltinType),
}
impl_froms!(
TypableDef: Function,
Struct,
Union,
Enum,
EnumVariant,
TypeAlias,
Const,
Static,
BuiltinType
);
impl_froms!(TypableDef: Function, AdtDef, EnumVariant, TypeAlias, Const, Static, BuiltinType);
impl From<Struct> for TypableDef {
fn from(it: Struct) -> TypableDef {
TypableDef::AdtDef(AdtDef::Struct(it))
}
}
impl From<Enum> for TypableDef {
fn from(it: Enum) -> TypableDef {
TypableDef::AdtDef(AdtDef::Enum(it))
}
}
impl From<Union> for TypableDef {
fn from(it: Union) -> TypableDef {
TypableDef::AdtDef(AdtDef::Union(it))
}
}
impl From<ModuleDef> for Option<TypableDef> {
fn from(def: ModuleDef) -> Option<TypableDef> {
let res = match def {
ModuleDef::Function(f) => f.into(),
ModuleDef::Struct(s) => s.into(),
ModuleDef::Union(u) => u.into(),
ModuleDef::Enum(e) => e.into(),
ModuleDef::AdtDef(adt) => adt.into(),
ModuleDef::EnumVariant(v) => v.into(),
ModuleDef::TypeAlias(t) => t.into(),
ModuleDef::Const(v) => v.into(),

View file

@ -1,4 +1,4 @@
use hir::{Either, Resolution};
use hir::{AdtDef, Either, Resolution};
use ra_syntax::AstNode;
use test_utils::tested_by;
@ -37,19 +37,14 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
acc.add_resolution(ctx, name.to_string(), &res.def.map(hir::Resolution::Def));
}
}
hir::ModuleDef::Enum(_)
| hir::ModuleDef::Struct(_)
| hir::ModuleDef::Union(_)
| hir::ModuleDef::TypeAlias(_) => {
if let hir::ModuleDef::Enum(e) = def {
hir::ModuleDef::AdtDef(_) | hir::ModuleDef::TypeAlias(_) => {
if let hir::ModuleDef::AdtDef(AdtDef::Enum(e)) = def {
for variant in e.variants(ctx.db) {
acc.add_enum_variant(ctx, variant);
}
}
let ty = match def {
hir::ModuleDef::Enum(e) => e.ty(ctx.db),
hir::ModuleDef::Struct(s) => s.ty(ctx.db),
hir::ModuleDef::Union(u) => u.ty(ctx.db),
hir::ModuleDef::AdtDef(adt) => adt.ty(ctx.db),
hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db),
_ => unreachable!(),
};

View file

@ -15,7 +15,7 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
_ => continue,
};
match def {
hir::ModuleDef::Enum(..)
hir::ModuleDef::AdtDef(hir::AdtDef::Enum(..))
| hir::ModuleDef::EnumVariant(..)
| hir::ModuleDef::Const(..)
| hir::ModuleDef::Module(..) => (),

View file

@ -67,9 +67,15 @@ impl Completions {
Resolution::Def(Function(func)) => {
return self.add_function_with_name(ctx, Some(local_name), *func);
}
Resolution::Def(Struct(it)) => (CompletionItemKind::Struct, it.docs(ctx.db)),
Resolution::Def(Union(it)) => (CompletionItemKind::Struct, it.docs(ctx.db)),
Resolution::Def(Enum(it)) => (CompletionItemKind::Enum, it.docs(ctx.db)),
Resolution::Def(AdtDef(hir::AdtDef::Struct(it))) => {
(CompletionItemKind::Struct, it.docs(ctx.db))
}
Resolution::Def(AdtDef(hir::AdtDef::Union(it))) => {
(CompletionItemKind::Struct, it.docs(ctx.db))
}
Resolution::Def(AdtDef(hir::AdtDef::Enum(it))) => {
(CompletionItemKind::Enum, it.docs(ctx.db))
}
Resolution::Def(EnumVariant(it)) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)),
Resolution::Def(Const(it)) => (CompletionItemKind::Const, it.docs(ctx.db)),
Resolution::Def(Static(it)) => (CompletionItemKind::Static, it.docs(ctx.db)),

View file

@ -193,9 +193,7 @@ impl NavigationTarget {
let nav = match module_def {
hir::ModuleDef::Module(module) => NavigationTarget::from_module(db, module),
hir::ModuleDef::Function(func) => NavigationTarget::from_def_source(db, func),
hir::ModuleDef::Struct(it) => NavigationTarget::from_adt_def(db, it.into()),
hir::ModuleDef::Enum(it) => NavigationTarget::from_adt_def(db, it.into()),
hir::ModuleDef::Union(it) => NavigationTarget::from_adt_def(db, it.into()),
hir::ModuleDef::AdtDef(it) => NavigationTarget::from_adt_def(db, it),
hir::ModuleDef::Const(it) => NavigationTarget::from_def_source(db, it),
hir::ModuleDef::Static(it) => NavigationTarget::from_def_source(db, it),
hir::ModuleDef::EnumVariant(it) => NavigationTarget::from_def_source(db, it),

View file

@ -1,4 +1,4 @@
use hir::{HasSource, HirDisplay};
use hir::{AdtDef, HasSource, HirDisplay};
use ra_db::SourceDatabase;
use ra_syntax::{
algo::{
@ -129,9 +129,13 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
}
}
hir::ModuleDef::Function(it) => res.extend(from_def_source(db, it)),
hir::ModuleDef::Struct(it) => res.extend(from_def_source(db, it)),
hir::ModuleDef::Union(it) => res.extend(from_def_source(db, it)),
hir::ModuleDef::Enum(it) => res.extend(from_def_source(db, it)),
hir::ModuleDef::AdtDef(AdtDef::Struct(it)) => {
res.extend(from_def_source(db, it))
}
hir::ModuleDef::AdtDef(AdtDef::Union(it)) => {
res.extend(from_def_source(db, it))
}
hir::ModuleDef::AdtDef(AdtDef::Enum(it)) => res.extend(from_def_source(db, it)),
hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)),
hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)),
hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)),

View file

@ -107,9 +107,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
Some(AssocItem(hir::ImplItem::TypeAlias(_))) => "type",
Some(Def(hir::ModuleDef::Module(_))) => "module",
Some(Def(hir::ModuleDef::Function(_))) => "function",
Some(Def(hir::ModuleDef::Struct(_))) => "type",
Some(Def(hir::ModuleDef::Union(_))) => "type",
Some(Def(hir::ModuleDef::Enum(_))) => "type",
Some(Def(hir::ModuleDef::AdtDef(_))) => "type",
Some(Def(hir::ModuleDef::EnumVariant(_))) => "constant",
Some(Def(hir::ModuleDef::Const(_))) => "constant",
Some(Def(hir::ModuleDef::Static(_))) => "constant",