@@ -67,16 +67,14 @@ pub enum Target {
6767 PatField ,
6868 ExprField ,
6969 WherePredicate ,
70-
71- // Used for attributes
7270 MacroCall ,
7371 Crate ,
7472 Delegation ,
7573}
7674
7775impl Display for Target {
7876 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
79- write ! ( f, "{}" , Self :: name ( * self ) )
77+ write ! ( f, "{}" , Self :: plural_name ( * self ) )
8078 }
8179}
8280
@@ -261,74 +259,105 @@ impl Target {
261259 }
262260 }
263261
264- pub fn is_function_like ( & self ) -> bool {
262+ pub fn singular_name ( self ) -> & ' static str {
265263 match self {
266- Target :: Fn | Target :: Closure | Target :: Method ( _) | Target :: ForeignFn => true ,
267- _ => false ,
268- }
269- }
270-
271- pub fn article ( self ) -> & ' static str {
272- match self {
273- Target :: ExternCrate
274- | Target :: Enum
275- | Target :: Impl { .. }
276- | Target :: Expression
277- | Target :: Arm
278- | Target :: AssocConst
279- | Target :: AssocTy => "an" ,
280- _ => "a" ,
264+ Target :: ExternCrate => "an extern crate" ,
265+ Target :: Use => "a use statement" ,
266+ Target :: Static => "a static" ,
267+ Target :: Const => "a constant" ,
268+ Target :: Fn => "a function" ,
269+ Target :: Closure => "a closure" ,
270+ Target :: Mod => "a module" ,
271+ Target :: ForeignMod => "a foreign module" ,
272+ Target :: GlobalAsm => "a global asm" ,
273+ Target :: TyAlias => "a type alias" ,
274+ Target :: Enum => "an enum" ,
275+ Target :: Variant => "an enum variant" ,
276+ Target :: Struct => "a struct" ,
277+ Target :: Field => "a struct field" ,
278+ Target :: Union => "a union" ,
279+ Target :: Trait => "a trait" ,
280+ Target :: TraitAlias => "a trait alias" ,
281+ Target :: Impl { of_trait : false } => "an inherent impl block" ,
282+ Target :: Impl { of_trait : true } => "a trait impl block" ,
283+ Target :: Expression => "an expression" ,
284+ Target :: Statement => "a statement" ,
285+ Target :: Arm => "a match arm" ,
286+ Target :: AssocConst => "an associated const" ,
287+ Target :: Method ( kind) => match kind {
288+ MethodKind :: Inherent => "an inherent method" ,
289+ MethodKind :: Trait { body : false } => "a required trait method" ,
290+ MethodKind :: Trait { body : true } => "a provided trait method" ,
291+ MethodKind :: TraitImpl => "a trait method in an impl block" ,
292+ } ,
293+ Target :: AssocTy => "an associated type" ,
294+ Target :: ForeignFn => "a foreign function" ,
295+ Target :: ForeignStatic => "a foreign static" ,
296+ Target :: ForeignTy => "a foreign type" ,
297+ Target :: GenericParam { kind, has_default : _ } => match kind {
298+ GenericParamKind :: Type => "a type parameter" ,
299+ GenericParamKind :: Lifetime => "a lifetime parameter" ,
300+ GenericParamKind :: Const => "a const parameter" ,
301+ } ,
302+ Target :: MacroDef => "a macro def" ,
303+ Target :: Param => "a function param" ,
304+ Target :: PatField => "a pattern field" ,
305+ Target :: ExprField => "a struct field" ,
306+ Target :: WherePredicate => "a where predicate" ,
307+ Target :: MacroCall => "a macro call" ,
308+ Target :: Crate => "a crate" ,
309+ Target :: Delegation => "a delegation" ,
281310 }
282311 }
283312
284- pub fn name ( self ) -> & ' static str {
313+ pub fn plural_name ( self ) -> & ' static str {
285314 match self {
286- Target :: ExternCrate => "extern crate " ,
287- Target :: Use => "use" ,
288- Target :: Static => "static item " ,
289- Target :: Const => "constant item " ,
290- Target :: Fn => "function " ,
291- Target :: Closure => "closure " ,
292- Target :: Mod => "module " ,
293- Target :: ForeignMod => "foreign module " ,
294- Target :: GlobalAsm => "global asm " ,
295- Target :: TyAlias => "type alias " ,
296- Target :: Enum => "enum " ,
297- Target :: Variant => "enum variant " ,
298- Target :: Struct => "struct " ,
299- Target :: Field => "struct field " ,
300- Target :: Union => "union " ,
301- Target :: Trait => "trait " ,
302- Target :: TraitAlias => "trait alias " ,
303- Target :: Impl { of_trait : false } => "inherent implementation block " ,
304- Target :: Impl { of_trait : true } => "trait implementation block " ,
305- Target :: Expression => "expression " ,
306- Target :: Statement => "statement " ,
307- Target :: Arm => "match arm " ,
308- Target :: AssocConst => "associated const " ,
315+ Target :: ExternCrate => "extern crates " ,
316+ Target :: Use => "use statements " ,
317+ Target :: Static => "statics " ,
318+ Target :: Const => "constants " ,
319+ Target :: Fn => "functions " ,
320+ Target :: Closure => "closures " ,
321+ Target :: Mod => "modules " ,
322+ Target :: ForeignMod => "foreign modules " ,
323+ Target :: GlobalAsm => "global asms " ,
324+ Target :: TyAlias => "type aliases " ,
325+ Target :: Enum => "enums " ,
326+ Target :: Variant => "enum variants " ,
327+ Target :: Struct => "structs " ,
328+ Target :: Field => "struct fields " ,
329+ Target :: Union => "unions " ,
330+ Target :: Trait => "traits " ,
331+ Target :: TraitAlias => "trait aliases " ,
332+ Target :: Impl { of_trait : false } => "inherent impl blocks " ,
333+ Target :: Impl { of_trait : true } => "trait impl blocks " ,
334+ Target :: Expression => "expressions " ,
335+ Target :: Statement => "statements " ,
336+ Target :: Arm => "match arms " ,
337+ Target :: AssocConst => "associated consts " ,
309338 Target :: Method ( kind) => match kind {
310- MethodKind :: Inherent => "inherent method " ,
311- MethodKind :: Trait { body : false } => "required trait method " ,
312- MethodKind :: Trait { body : true } => "provided trait method " ,
313- MethodKind :: TraitImpl => "trait method in implementation bloock " ,
339+ MethodKind :: Inherent => "inherent methods " ,
340+ MethodKind :: Trait { body : false } => "required trait methods " ,
341+ MethodKind :: Trait { body : true } => "provided trait methods " ,
342+ MethodKind :: TraitImpl => "trait method in an impl blocks " ,
314343 } ,
315- Target :: AssocTy => "associated type " ,
316- Target :: ForeignFn => "foreign function " ,
317- Target :: ForeignStatic => "foreign static item " ,
318- Target :: ForeignTy => "foreign type " ,
344+ Target :: AssocTy => "associated types " ,
345+ Target :: ForeignFn => "foreign functions " ,
346+ Target :: ForeignStatic => "foreign statics " ,
347+ Target :: ForeignTy => "foreign types " ,
319348 Target :: GenericParam { kind, has_default : _ } => match kind {
320- GenericParamKind :: Type => "type parameter " ,
321- GenericParamKind :: Lifetime => "lifetime parameter " ,
322- GenericParamKind :: Const => "const parameter " ,
349+ GenericParamKind :: Type => "type parameters " ,
350+ GenericParamKind :: Lifetime => "lifetime parameters " ,
351+ GenericParamKind :: Const => "const parameters " ,
323352 } ,
324- Target :: MacroDef => "macro def " ,
325- Target :: Param => "function param " ,
326- Target :: PatField => "pattern field " ,
327- Target :: ExprField => "struct field " ,
328- Target :: WherePredicate => "where predicate " ,
329- Target :: MacroCall => "macro call " ,
330- Target :: Crate => "crate " ,
331- Target :: Delegation => "delegation " ,
353+ Target :: MacroDef => "macro defs " ,
354+ Target :: Param => "function params " ,
355+ Target :: PatField => "pattern fields " ,
356+ Target :: ExprField => "struct fields " ,
357+ Target :: WherePredicate => "where predicates " ,
358+ Target :: MacroCall => "macro calls " ,
359+ Target :: Crate => "crates " ,
360+ Target :: Delegation => "delegations " ,
332361 }
333362 }
334363}
0 commit comments