+impl DefKind {
+ pub fn descr(self) -> &'static str {
+ match self {
+ DefKind::Fn => "function",
+ DefKind::Mod => "module",
+ DefKind::Static => "static",
+ DefKind::Enum => "enum",
+ DefKind::Variant => "variant",
+ DefKind::Ctor(CtorOf::Variant, CtorKind::Fn) => "tuple variant",
+ DefKind::Ctor(CtorOf::Variant, CtorKind::Const) => "unit variant",
+ DefKind::Ctor(CtorOf::Variant, CtorKind::Fictive) => "struct variant",
+ DefKind::Struct => "struct",
+ DefKind::Ctor(CtorOf::Struct, CtorKind::Fn) => "tuple struct",
+ DefKind::Ctor(CtorOf::Struct, CtorKind::Const) => "unit struct",
+ DefKind::Ctor(CtorOf::Struct, CtorKind::Fictive) =>
+ bug!("impossible struct constructor"),
+ DefKind::Existential => "existential type",
+ DefKind::TyAlias => "type alias",
+ DefKind::TraitAlias => "trait alias",
+ DefKind::AssociatedTy => "associated type",
+ DefKind::AssociatedExistential => "associated existential type",
+ DefKind::Union => "union",
+ DefKind::Trait => "trait",
+ DefKind::ForeignTy => "foreign type",
+ DefKind::Method => "method",
+ DefKind::Const => "constant",
+ DefKind::AssociatedConst => "associated constant",
+ DefKind::TyParam => "type parameter",
+ DefKind::ConstParam => "const parameter",
+ DefKind::Macro(macro_kind) => macro_kind.descr(),
+ }
+ }
+
+ /// An English article for the def.
+ pub fn article(&self) -> &'static str {
+ match *self {
+ DefKind::AssociatedTy
+ | DefKind::AssociatedConst
+ | DefKind::AssociatedExistential
+ | DefKind::Enum
+ | DefKind::Existential => "an",
+ DefKind::Macro(macro_kind) => macro_kind.article(),
+ _ => "a",
+ }
+ }
+}
+