mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-04 01:08:47 +00:00
59 lines
1.9 KiB
Rust
59 lines
1.9 KiB
Rust
|
use hir_def::{AdtId, EnumVariantId, ModuleDefId};
|
||
|
|
||
|
use crate::{Adt, EnumVariant, ModuleDef};
|
||
|
|
||
|
macro_rules! from_id {
|
||
|
($(($id:path, $ty:path)),*) => {$(
|
||
|
impl From<$id> for $ty {
|
||
|
fn from(id: $id) -> $ty {
|
||
|
$ty { id }
|
||
|
}
|
||
|
}
|
||
|
)*}
|
||
|
}
|
||
|
|
||
|
from_id![
|
||
|
(hir_def::ModuleId, crate::Module),
|
||
|
(hir_def::StructId, crate::Struct),
|
||
|
(hir_def::UnionId, crate::Union),
|
||
|
(hir_def::EnumId, crate::Enum),
|
||
|
(hir_def::TypeAliasId, crate::TypeAlias),
|
||
|
(hir_def::TraitId, crate::Trait),
|
||
|
(hir_def::StaticId, crate::Static),
|
||
|
(hir_def::ConstId, crate::Const),
|
||
|
(hir_def::FunctionId, crate::Function),
|
||
|
(hir_expand::MacroDefId, crate::MacroDef)
|
||
|
];
|
||
|
|
||
|
impl From<AdtId> for Adt {
|
||
|
fn from(id: AdtId) -> Self {
|
||
|
match id {
|
||
|
AdtId::StructId(it) => Adt::Struct(it.into()),
|
||
|
AdtId::UnionId(it) => Adt::Union(it.into()),
|
||
|
AdtId::EnumId(it) => Adt::Enum(it.into()),
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl From<EnumVariantId> for EnumVariant {
|
||
|
fn from(id: EnumVariantId) -> Self {
|
||
|
EnumVariant { parent: id.parent.into(), id: id.local_id }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl From<ModuleDefId> for ModuleDef {
|
||
|
fn from(id: ModuleDefId) -> Self {
|
||
|
match id {
|
||
|
ModuleDefId::ModuleId(it) => ModuleDef::Module(it.into()),
|
||
|
ModuleDefId::FunctionId(it) => ModuleDef::Function(it.into()),
|
||
|
ModuleDefId::AdtId(it) => ModuleDef::Adt(it.into()),
|
||
|
ModuleDefId::EnumVariantId(it) => ModuleDef::EnumVariant(it.into()),
|
||
|
ModuleDefId::ConstId(it) => ModuleDef::Const(it.into()),
|
||
|
ModuleDefId::StaticId(it) => ModuleDef::Static(it.into()),
|
||
|
ModuleDefId::TraitId(it) => ModuleDef::Trait(it.into()),
|
||
|
ModuleDefId::TypeAliasId(it) => ModuleDef::TypeAlias(it.into()),
|
||
|
ModuleDefId::BuiltinType(it) => ModuleDef::BuiltinType(it),
|
||
|
}
|
||
|
}
|
||
|
}
|