@@ -80,6 +80,53 @@ pub enum DefKind {
8080 Macro ( MacroKind ) ,
8181}
8282
83+ impl DefKind {
84+ pub fn descr ( self ) -> & ' static str {
85+ match self {
86+ DefKind :: Fn => "function" ,
87+ DefKind :: Mod => "module" ,
88+ DefKind :: Static => "static" ,
89+ DefKind :: Enum => "enum" ,
90+ DefKind :: Variant => "variant" ,
91+ DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Fn ) => "tuple variant" ,
92+ DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Const ) => "unit variant" ,
93+ DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Fictive ) => "struct variant" ,
94+ DefKind :: Struct => "struct" ,
95+ DefKind :: Ctor ( CtorOf :: Struct , CtorKind :: Fn ) => "tuple struct" ,
96+ DefKind :: Ctor ( CtorOf :: Struct , CtorKind :: Const ) => "unit struct" ,
97+ DefKind :: Ctor ( CtorOf :: Struct , CtorKind :: Fictive ) =>
98+ bug ! ( "impossible struct constructor" ) ,
99+ DefKind :: Existential => "existential type" ,
100+ DefKind :: TyAlias => "type alias" ,
101+ DefKind :: TraitAlias => "trait alias" ,
102+ DefKind :: AssociatedTy => "associated type" ,
103+ DefKind :: AssociatedExistential => "associated existential type" ,
104+ DefKind :: Union => "union" ,
105+ DefKind :: Trait => "trait" ,
106+ DefKind :: ForeignTy => "foreign type" ,
107+ DefKind :: Method => "method" ,
108+ DefKind :: Const => "constant" ,
109+ DefKind :: AssociatedConst => "associated constant" ,
110+ DefKind :: TyParam => "type parameter" ,
111+ DefKind :: ConstParam => "const parameter" ,
112+ DefKind :: Macro ( macro_kind) => macro_kind. descr ( ) ,
113+ }
114+ }
115+
116+ /// An English article for the def.
117+ pub fn article ( & self ) -> & ' static str {
118+ match * self {
119+ DefKind :: AssociatedTy
120+ | DefKind :: AssociatedConst
121+ | DefKind :: AssociatedExistential
122+ | DefKind :: Enum
123+ | DefKind :: Existential => "an" ,
124+ DefKind :: Macro ( macro_kind) => macro_kind. article ( ) ,
125+ _ => "a" ,
126+ }
127+ }
128+ }
129+
83130#[ derive( Clone , Copy , PartialEq , Eq , RustcEncodable , RustcDecodable , Hash , Debug , HashStable ) ]
84131pub enum Def < Id = hir:: HirId > {
85132 Def ( DefKind , DefId ) ,
@@ -328,39 +375,13 @@ impl<Id> Def<Id> {
328375 /// A human readable name for the def kind ("function", "module", etc.).
329376 pub fn kind_name ( & self ) -> & ' static str {
330377 match * self {
331- Def :: Def ( DefKind :: Fn , _) => "function" ,
332- Def :: Def ( DefKind :: Mod , _) => "module" ,
333- Def :: Def ( DefKind :: Static , _) => "static" ,
334- Def :: Def ( DefKind :: Enum , _) => "enum" ,
335- Def :: Def ( DefKind :: Variant , _) => "variant" ,
336- Def :: Def ( DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Fn ) , _) => "tuple variant" ,
337- Def :: Def ( DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Const ) , _) => "unit variant" ,
338- Def :: Def ( DefKind :: Ctor ( CtorOf :: Variant , CtorKind :: Fictive ) , _) => "struct variant" ,
339- Def :: Def ( DefKind :: Struct , _) => "struct" ,
340- Def :: Def ( DefKind :: Ctor ( CtorOf :: Struct , CtorKind :: Fn ) , _) => "tuple struct" ,
341- Def :: Def ( DefKind :: Ctor ( CtorOf :: Struct , CtorKind :: Const ) , _) => "unit struct" ,
342- Def :: Def ( DefKind :: Ctor ( CtorOf :: Struct , CtorKind :: Fictive ) , _) =>
343- bug ! ( "impossible struct constructor" ) ,
344- Def :: Def ( DefKind :: Existential , _) => "existential type" ,
345- Def :: Def ( DefKind :: TyAlias , _) => "type alias" ,
346- Def :: Def ( DefKind :: TraitAlias , _) => "trait alias" ,
347- Def :: Def ( DefKind :: AssociatedTy , _) => "associated type" ,
348- Def :: Def ( DefKind :: AssociatedExistential , _) => "associated existential type" ,
378+ Def :: Def ( kind, _) => kind. descr ( ) ,
349379 Def :: SelfCtor ( ..) => "self constructor" ,
350- Def :: Def ( DefKind :: Union , _) => "union" ,
351- Def :: Def ( DefKind :: Trait , _) => "trait" ,
352- Def :: Def ( DefKind :: ForeignTy , _) => "foreign type" ,
353- Def :: Def ( DefKind :: Method , _) => "method" ,
354- Def :: Def ( DefKind :: Const , _) => "constant" ,
355- Def :: Def ( DefKind :: AssociatedConst , _) => "associated constant" ,
356- Def :: Def ( DefKind :: TyParam , _) => "type parameter" ,
357- Def :: Def ( DefKind :: ConstParam , _) => "const parameter" ,
358380 Def :: PrimTy ( ..) => "builtin type" ,
359381 Def :: Local ( ..) => "local variable" ,
360382 Def :: Upvar ( ..) => "closure capture" ,
361383 Def :: Label ( ..) => "label" ,
362384 Def :: SelfTy ( ..) => "self type" ,
363- Def :: Def ( DefKind :: Macro ( macro_kind) , _) => macro_kind. descr ( ) ,
364385 Def :: ToolMod => "tool module" ,
365386 Def :: NonMacroAttr ( attr_kind) => attr_kind. descr ( ) ,
366387 Def :: Err => "unresolved item" ,
@@ -370,13 +391,8 @@ impl<Id> Def<Id> {
370391 /// An English article for the def.
371392 pub fn article ( & self ) -> & ' static str {
372393 match * self {
373- Def :: Def ( DefKind :: AssociatedTy , _)
374- | Def :: Def ( DefKind :: AssociatedConst , _)
375- | Def :: Def ( DefKind :: AssociatedExistential , _)
376- | Def :: Def ( DefKind :: Enum , _)
377- | Def :: Def ( DefKind :: Existential , _)
378- | Def :: Err => "an" ,
379- Def :: Def ( DefKind :: Macro ( macro_kind) , _) => macro_kind. article ( ) ,
394+ Def :: Def ( kind, _) => kind. article ( ) ,
395+ Def :: Err => "an" ,
380396 _ => "a" ,
381397 }
382398 }
0 commit comments