Explicitly match all DefKind item in conversion to TypeKind

This commit is contained in:
Guillaume Gomez 2021-01-12 13:58:16 +01:00
parent f9435f4c92
commit d5174a4b0d

View File

@ -1304,6 +1304,49 @@ crate enum TypeKind {
Primitive,
}
impl<'a> From<&'a hir::def::DefKind> for TypeKind {
fn from(other: &hir::def::DefKind) -> Self {
Self::from(*other)
}
}
impl From<hir::def::DefKind> for TypeKind {
fn from(other: hir::def::DefKind) -> Self {
match other {
hir::def::DefKind::Enum => Self::Enum,
hir::def::DefKind::Fn => Self::Function,
hir::def::DefKind::Mod => Self::Module,
hir::def::DefKind::Const => Self::Const,
hir::def::DefKind::Static => Self::Static,
hir::def::DefKind::Struct => Self::Struct,
hir::def::DefKind::Union => Self::Union,
hir::def::DefKind::Trait => Self::Trait,
hir::def::DefKind::TyAlias => Self::Typedef,
hir::def::DefKind::ForeignTy => Self::Foreign,
hir::def::DefKind::TraitAlias => Self::TraitAlias,
hir::def::DefKind::Macro(_) => Self::Macro,
hir::def::DefKind::Variant
| hir::def::DefKind::AssocTy
| hir::def::DefKind::TyParam
| hir::def::DefKind::ConstParam
| hir::def::DefKind::Ctor(..)
| hir::def::DefKind::AssocFn
| hir::def::DefKind::AssocConst
| hir::def::DefKind::ExternCrate
| hir::def::DefKind::Use
| hir::def::DefKind::ForeignMod
| hir::def::DefKind::AnonConst
| hir::def::DefKind::OpaqueTy
| hir::def::DefKind::Field
| hir::def::DefKind::LifetimeParam
| hir::def::DefKind::GlobalAsm
| hir::def::DefKind::Impl
| hir::def::DefKind::Closure
| hir::def::DefKind::Generator => Self::Foreign,
}
}
}
crate trait GetDefId {
/// Use this method to get the [`DefId`] of a [`clean`] AST node.
/// This will return [`None`] when called on a primitive [`clean::Type`].