Replace DefPathData::Misc by two appropriately-named variants.

This commit is contained in:
Camille GILLOT 2022-05-12 20:12:35 +02:00
parent 3a08bd7873
commit dde7bff574
3 changed files with 14 additions and 11 deletions

View File

@ -261,14 +261,16 @@ pub enum DefPathData {
// they are treated specially by the `def_path` function.
/// The crate root (marker).
CrateRoot,
// Catch-all for random `DefId` things like `DUMMY_NODE_ID`.
Misc,
// Different kinds of items and item-like things:
/// An impl.
Impl,
/// An `extern` block.
ForeignMod,
/// A `use` item.
Use,
/// A global asm item.
GlobalAsm,
/// Something in the type namespace.
TypeNs(Symbol),
/// Something in the value namespace.
@ -443,9 +445,8 @@ impl DefPathData {
match *self {
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
Impl | ForeignMod | CrateRoot | Misc | ClosureExpr | Ctor | AnonConst | ImplTrait => {
None
}
Impl | ForeignMod | CrateRoot | Use | GlobalAsm | ClosureExpr | Ctor | AnonConst
| ImplTrait => None,
}
}
@ -459,7 +460,8 @@ impl DefPathData {
CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
Impl => DefPathDataName::Anon { namespace: kw::Impl },
ForeignMod => DefPathDataName::Anon { namespace: kw::Extern },
Misc => DefPathDataName::Anon { namespace: sym::misc },
Use => DefPathDataName::Anon { namespace: kw::Use },
GlobalAsm => DefPathDataName::Anon { namespace: sym::global_asm },
ClosureExpr => DefPathDataName::Anon { namespace: sym::closure },
Ctor => DefPathDataName::Anon { namespace: sym::constructor },
AnonConst => DefPathDataName::Anon { namespace: sym::constant },

View File

@ -109,7 +109,7 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
visit::walk_item(self, i);
return self.visit_macro_invoc(i.id);
}
ItemKind::GlobalAsm(..) => DefPathData::Misc,
ItemKind::GlobalAsm(..) => DefPathData::GlobalAsm,
ItemKind::Use(..) => {
return visit::walk_item(self, i);
}
@ -160,11 +160,11 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
}
fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
self.create_def(id, DefPathData::Misc, use_tree.span);
self.create_def(id, DefPathData::Use, use_tree.span);
match use_tree.kind {
UseTreeKind::Simple(_, id1, id2) => {
self.create_def(id1, DefPathData::Misc, use_tree.prefix.span);
self.create_def(id2, DefPathData::Misc, use_tree.prefix.span);
self.create_def(id1, DefPathData::Use, use_tree.prefix.span);
self.create_def(id2, DefPathData::Use, use_tree.prefix.span);
}
UseTreeKind::Glob => (),
UseTreeKind::Nested(..) => {}

View File

@ -788,7 +788,8 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
// These should never show up as `path_append` arguments.
DefPathData::CrateRoot
| DefPathData::Misc
| DefPathData::Use
| DefPathData::GlobalAsm
| DefPathData::Impl
| DefPathData::MacroNs(_)
| DefPathData::LifetimeNs(_) => {