diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index e509ec3f021..cbe871bd65a 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -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 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`].