Fix handling of item names for HIR

- Handle variants, fields, macros in `Node::ident()`
- Handle the crate root in `opt_item_name`
- Factor out `item_name_from_def_id` to reduce duplication
- Look at HIR before the DefId for `opt_item_name`

  This gives accurate spans, which are not available from serialized
  metadata.

- Don't panic on the crate root in `opt_item_name`
- Add comments
This commit is contained in:
Joshua Nelson
2020-10-21 22:00:32 -04:00
parent dc06a36074
commit 67d0db6b00
3 changed files with 49 additions and 21 deletions

View File

@@ -478,7 +478,7 @@ impl<'hir> Map<'hir> {
}
pub fn get_if_local(&self, id: DefId) -> Option<Node<'hir>> {
id.as_local().map(|id| self.get(self.local_def_id_to_hir_id(id)))
id.as_local().and_then(|id| self.find(self.local_def_id_to_hir_id(id)))
}
pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics<'hir>> {