@@ -128,14 +128,6 @@ impl PathResolution {
128
128
pub fn unresolved_segments ( & self ) -> usize {
129
129
self . unresolved_segments
130
130
}
131
-
132
- pub fn kind_name ( & self ) -> & ' static str {
133
- if self . unresolved_segments != 0 {
134
- "associated item"
135
- } else {
136
- self . base_def . kind_name ( )
137
- }
138
- }
139
131
}
140
132
141
133
/// Different kinds of symbols don't influence each other.
@@ -269,27 +261,33 @@ impl NonMacroAttrKind {
269
261
270
262
impl Def {
271
263
pub fn def_id ( & self ) -> DefId {
264
+ self . opt_def_id ( ) . unwrap_or_else ( || {
265
+ bug ! ( "attempted .def_id() on invalid def: {:?}" , self )
266
+ } )
267
+ }
268
+
269
+ pub fn opt_def_id ( & self ) -> Option < DefId > {
272
270
match * self {
273
271
Def :: Fn ( id) | Def :: Mod ( id) | Def :: Static ( id, _) |
274
272
Def :: Variant ( id) | Def :: VariantCtor ( id, ..) | Def :: Enum ( id) |
275
273
Def :: TyAlias ( id) | Def :: TraitAlias ( id) |
276
274
Def :: AssociatedTy ( id) | Def :: TyParam ( id) | Def :: Struct ( id) | Def :: StructCtor ( id, ..) |
277
275
Def :: Union ( id) | Def :: Trait ( id) | Def :: Method ( id) | Def :: Const ( id) |
278
276
Def :: AssociatedConst ( id) | Def :: Macro ( id, ..) |
279
- Def :: Existential ( id) | Def :: AssociatedExistential ( id) | Def :: ForeignTy ( id) |
280
- Def :: SelfCtor ( id) => {
281
- id
277
+ Def :: Existential ( id) | Def :: AssociatedExistential ( id) | Def :: ForeignTy ( id) => {
278
+ Some ( id)
282
279
}
283
280
284
281
Def :: Local ( ..) |
285
282
Def :: Upvar ( ..) |
286
283
Def :: Label ( ..) |
287
284
Def :: PrimTy ( ..) |
288
285
Def :: SelfTy ( ..) |
286
+ Def :: SelfCtor ( ..) |
289
287
Def :: ToolMod |
290
288
Def :: NonMacroAttr ( ..) |
291
289
Def :: Err => {
292
- bug ! ( "attempted .def_id() on invalid def: {:?}" , self )
290
+ None
293
291
}
294
292
}
295
293
}
@@ -333,4 +331,13 @@ impl Def {
333
331
Def :: Err => "unresolved item" ,
334
332
}
335
333
}
334
+
335
+ pub fn article ( & self ) -> & ' static str {
336
+ match * self {
337
+ Def :: AssociatedTy ( ..) | Def :: AssociatedConst ( ..) | Def :: AssociatedExistential ( ..) |
338
+ Def :: Enum ( ..) | Def :: Existential ( ..) | Def :: Err => "an" ,
339
+ Def :: Macro ( .., macro_kind) => macro_kind. article ( ) ,
340
+ _ => "a" ,
341
+ }
342
+ }
336
343
}
0 commit comments