@@ -60,51 +60,7 @@ pub enum Target {
60
60
61
61
impl Display for Target {
62
62
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
63
- write ! (
64
- f,
65
- "{}" ,
66
- match * self {
67
- Target :: ExternCrate => "extern crate" ,
68
- Target :: Use => "use" ,
69
- Target :: Static => "static item" ,
70
- Target :: Const => "constant item" ,
71
- Target :: Fn => "function" ,
72
- Target :: Closure => "closure" ,
73
- Target :: Mod => "module" ,
74
- Target :: ForeignMod => "foreign module" ,
75
- Target :: GlobalAsm => "global asm" ,
76
- Target :: TyAlias => "type alias" ,
77
- Target :: OpaqueTy => "opaque type" ,
78
- Target :: Enum => "enum" ,
79
- Target :: Variant => "enum variant" ,
80
- Target :: Struct => "struct" ,
81
- Target :: Field => "struct field" ,
82
- Target :: Union => "union" ,
83
- Target :: Trait => "trait" ,
84
- Target :: TraitAlias => "trait alias" ,
85
- Target :: Impl => "item" ,
86
- Target :: Expression => "expression" ,
87
- Target :: Statement => "statement" ,
88
- Target :: Arm => "match arm" ,
89
- Target :: AssocConst => "associated const" ,
90
- Target :: Method ( kind) => match kind {
91
- MethodKind :: Inherent => "inherent method" ,
92
- MethodKind :: Trait { body: false } => "required trait method" ,
93
- MethodKind :: Trait { body: true } => "provided trait method" ,
94
- } ,
95
- Target :: AssocTy => "associated type" ,
96
- Target :: ForeignFn => "foreign function" ,
97
- Target :: ForeignStatic => "foreign static item" ,
98
- Target :: ForeignTy => "foreign type" ,
99
- Target :: GenericParam ( kind) => match kind {
100
- GenericParamKind :: Type => "type parameter" ,
101
- GenericParamKind :: Lifetime => "lifetime parameter" ,
102
- GenericParamKind :: Const => "const parameter" ,
103
- } ,
104
- Target :: MacroDef => "macro def" ,
105
- Target :: Param => "function param" ,
106
- }
107
- )
63
+ write ! ( f, "{}" , Self :: name( * self ) )
108
64
}
109
65
}
110
66
@@ -185,4 +141,48 @@ impl Target {
185
141
hir:: GenericParamKind :: Const { .. } => Target :: GenericParam ( GenericParamKind :: Const ) ,
186
142
}
187
143
}
144
+
145
+ pub fn name ( self ) -> & ' static str {
146
+ match self {
147
+ Target :: ExternCrate => "extern crate" ,
148
+ Target :: Use => "use" ,
149
+ Target :: Static => "static item" ,
150
+ Target :: Const => "constant item" ,
151
+ Target :: Fn => "function" ,
152
+ Target :: Closure => "closure" ,
153
+ Target :: Mod => "module" ,
154
+ Target :: ForeignMod => "foreign module" ,
155
+ Target :: GlobalAsm => "global asm" ,
156
+ Target :: TyAlias => "type alias" ,
157
+ Target :: OpaqueTy => "opaque type" ,
158
+ Target :: Enum => "enum" ,
159
+ Target :: Variant => "enum variant" ,
160
+ Target :: Struct => "struct" ,
161
+ Target :: Field => "struct field" ,
162
+ Target :: Union => "union" ,
163
+ Target :: Trait => "trait" ,
164
+ Target :: TraitAlias => "trait alias" ,
165
+ Target :: Impl => "implementation block" ,
166
+ Target :: Expression => "expression" ,
167
+ Target :: Statement => "statement" ,
168
+ Target :: Arm => "match arm" ,
169
+ Target :: AssocConst => "associated const" ,
170
+ Target :: Method ( kind) => match kind {
171
+ MethodKind :: Inherent => "inherent method" ,
172
+ MethodKind :: Trait { body : false } => "required trait method" ,
173
+ MethodKind :: Trait { body : true } => "provided trait method" ,
174
+ } ,
175
+ Target :: AssocTy => "associated type" ,
176
+ Target :: ForeignFn => "foreign function" ,
177
+ Target :: ForeignStatic => "foreign static item" ,
178
+ Target :: ForeignTy => "foreign type" ,
179
+ Target :: GenericParam ( kind) => match kind {
180
+ GenericParamKind :: Type => "type parameter" ,
181
+ GenericParamKind :: Lifetime => "lifetime parameter" ,
182
+ GenericParamKind :: Const => "const parameter" ,
183
+ } ,
184
+ Target :: MacroDef => "macro def" ,
185
+ Target :: Param => "function param" ,
186
+ }
187
+ }
188
188
}
0 commit comments