@@ -128,14 +128,6 @@ impl PathResolution {
128128 pub fn unresolved_segments ( & self ) -> usize {
129129 self . unresolved_segments
130130 }
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- }
139131}
140132
141133/// Different kinds of symbols don't influence each other.
@@ -269,27 +261,33 @@ impl NonMacroAttrKind {
269261
270262impl Def {
271263 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 > {
272270 match * self {
273271 Def :: Fn ( id) | Def :: Mod ( id) | Def :: Static ( id, _) |
274272 Def :: Variant ( id) | Def :: VariantCtor ( id, ..) | Def :: Enum ( id) |
275273 Def :: TyAlias ( id) | Def :: TraitAlias ( id) |
276274 Def :: AssociatedTy ( id) | Def :: TyParam ( id) | Def :: Struct ( id) | Def :: StructCtor ( id, ..) |
277275 Def :: Union ( id) | Def :: Trait ( id) | Def :: Method ( id) | Def :: Const ( id) |
278276 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)
282279 }
283280
284281 Def :: Local ( ..) |
285282 Def :: Upvar ( ..) |
286283 Def :: Label ( ..) |
287284 Def :: PrimTy ( ..) |
288285 Def :: SelfTy ( ..) |
286+ Def :: SelfCtor ( ..) |
289287 Def :: ToolMod |
290288 Def :: NonMacroAttr ( ..) |
291289 Def :: Err => {
292- bug ! ( "attempted .def_id() on invalid def: {:?}" , self )
290+ None
293291 }
294292 }
295293 }
@@ -333,4 +331,13 @@ impl Def {
333331 Def :: Err => "unresolved item" ,
334332 }
335333 }
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+ }
336343}
0 commit comments