Add DefPathData::NestedStatic instead of reusing DefPathData::AnonConst

This commit is contained in:
John Kåre Alsaker 2025-05-02 13:17:47 +02:00
parent ddff38703a
commit efc51ce993
5 changed files with 10 additions and 8 deletions

View file

@ -17,14 +17,13 @@ use hir::def::DefKind;
use rustc_ast::Mutability;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_hir as hir;
use rustc_hir::definitions::DisambiguatorState;
use rustc_hir::definitions::{DefPathData, DisambiguatorState};
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
use rustc_middle::mir::interpret::{ConstAllocation, CtfeProvenance, InterpResult};
use rustc_middle::query::TyCtxtAt;
use rustc_middle::span_bug;
use rustc_middle::ty::layout::TyAndLayout;
use rustc_span::def_id::LocalDefId;
use rustc_span::sym;
use tracing::{instrument, trace};
use super::{
@ -108,9 +107,9 @@ fn intern_as_new_static<'tcx>(
) {
let feed = tcx.create_def(
static_id,
Some(sym::nested),
DefKind::Static { safety: hir::Safety::Safe, mutability: alloc.0.mutability, nested: true },
None,
DefKind::Static { safety: hir::Safety::Safe, mutability: alloc.0.mutability, nested: true },
Some(DefPathData::NestedStatic),
disambiguator,
);
tcx.set_nested_alloc_id_static(alloc_id, feed.def_id());

View file

@ -273,9 +273,6 @@ impl DefKind {
// but those provide their own DefPathData.
DefKind::AssocTy => DefPathData::TypeNs(name.unwrap()),
// It's not exactly an anon const, but wrt DefPathData, there
// is no difference.
DefKind::Static { nested: true, .. } => DefPathData::AnonConst,
DefKind::Fn
| DefKind::Const
| DefKind::ConstParam

View file

@ -313,6 +313,8 @@ pub enum DefPathData {
AnonAssocTy(Symbol),
/// A synthetic body for a coroutine's by-move body.
SyntheticCoroutineBody,
/// Additional static data referred to by a static.
NestedStatic,
}
impl Definitions {
@ -455,7 +457,8 @@ impl DefPathData {
| Ctor
| AnonConst
| OpaqueTy
| SyntheticCoroutineBody => None,
| SyntheticCoroutineBody
| NestedStatic => None,
}
}
@ -477,6 +480,7 @@ impl DefPathData {
OpaqueTy => DefPathDataName::Anon { namespace: sym::opaque },
AnonAssocTy(..) => DefPathDataName::Anon { namespace: sym::anon_assoc },
SyntheticCoroutineBody => DefPathDataName::Anon { namespace: sym::synthetic },
NestedStatic => DefPathDataName::Anon { namespace: sym::nested },
}
}
}

View file

@ -717,6 +717,7 @@ fn encode_ty_name(tcx: TyCtxt<'_>, def_id: DefId) -> String {
hir::definitions::DefPathData::AnonConst => "k",
hir::definitions::DefPathData::OpaqueTy => "i",
hir::definitions::DefPathData::SyntheticCoroutineBody => "s",
hir::definitions::DefPathData::NestedStatic => "n",
hir::definitions::DefPathData::CrateRoot
| hir::definitions::DefPathData::Use
| hir::definitions::DefPathData::GlobalAsm

View file

@ -851,6 +851,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
DefPathData::AnonConst => 'k',
DefPathData::OpaqueTy => 'i',
DefPathData::SyntheticCoroutineBody => 's',
DefPathData::NestedStatic => 'n',
// These should never show up as `path_append` arguments.
DefPathData::CrateRoot