1
Fork 0

Rollup merge of #139662 - nnethercote:tweak-DefPathData, r=compiler-errors

Tweak `DefPathData`

Some improvements in and around `DefPathData`, following on from #137977.

r? `@spastorino`
This commit is contained in:
Jacob Pratt 2025-04-11 21:21:01 +02:00 committed by GitHub
commit 2b54f9bfb1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 48 additions and 44 deletions

View file

@ -267,11 +267,16 @@ impl DefKind {
| DefKind::ForeignTy
| DefKind::TraitAlias
| DefKind::TyParam
| DefKind::ExternCrate => DefPathData::TypeNs(Some(name.unwrap())),
| DefKind::ExternCrate => DefPathData::TypeNs(name.unwrap()),
// An associated type names will be missing for an RPITIT. It will
// later be given a name with `synthetic` in it, if necessary.
DefKind::AssocTy => DefPathData::TypeNs(name),
// An associated type name will be missing for an RPITIT.
DefKind::AssocTy => {
if let Some(name) = name {
DefPathData::TypeNs(name)
} else {
DefPathData::AnonAssocTy
}
}
// It's not exactly an anon const, but wrt DefPathData, there
// is no difference.

View file

@ -271,9 +271,8 @@ pub enum DefPathData {
Use,
/// A global asm item.
GlobalAsm,
/// Something in the type namespace. Will be empty for RPITIT associated
/// types, which are given a synthetic name later, if necessary.
TypeNs(Option<Symbol>),
/// Something in the type namespace.
TypeNs(Symbol),
/// Something in the value namespace.
ValueNs(Symbol),
/// Something in the macro namespace.
@ -291,6 +290,8 @@ pub enum DefPathData {
/// An existential `impl Trait` type node.
/// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name.
OpaqueTy,
/// An anonymous associated type from an RPITIT.
AnonAssocTy,
/// A synthetic body for a coroutine's by-move body.
SyntheticCoroutineBody,
}
@ -413,9 +414,7 @@ impl DefPathData {
pub fn get_opt_name(&self) -> Option<Symbol> {
use self::DefPathData::*;
match *self {
TypeNs(name) => name,
ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
Impl
| ForeignMod
@ -426,6 +425,7 @@ impl DefPathData {
| Ctor
| AnonConst
| OpaqueTy
| AnonAssocTy
| SyntheticCoroutineBody => None,
}
}
@ -433,14 +433,9 @@ impl DefPathData {
pub fn name(&self) -> DefPathDataName {
use self::DefPathData::*;
match *self {
TypeNs(name) => {
if let Some(name) = name {
DefPathDataName::Named(name)
} else {
DefPathDataName::Anon { namespace: sym::synthetic }
}
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => {
DefPathDataName::Named(name)
}
ValueNs(name) | MacroNs(name) | LifetimeNs(name) => DefPathDataName::Named(name),
// Note that this does not show up in user print-outs.
CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
Impl => DefPathDataName::Anon { namespace: kw::Impl },
@ -451,6 +446,7 @@ impl DefPathData {
Ctor => DefPathDataName::Anon { namespace: sym::constructor },
AnonConst => DefPathDataName::Anon { namespace: sym::constant },
OpaqueTy => DefPathDataName::Anon { namespace: sym::opaque },
AnonAssocTy => DefPathDataName::Anon { namespace: sym::anon_assoc },
SyntheticCoroutineBody => DefPathDataName::Anon { namespace: sym::synthetic },
}
}