Fix v0 symbol mangling for assoc const bindings

This commit is contained in:
León Orell Valerian Liehr
2026-01-08 08:51:34 +01:00
parent 8d524f096d
commit 4a6b5edba8
6 changed files with 62 additions and 6 deletions

View File

@@ -3356,9 +3356,9 @@ dependencies = [
[[package]]
name = "rustc-demangle"
version = "0.1.26"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace"
checksum = "b50b8869d9fc858ce7266cce0194bd74df58b9d0e3f6df3a9fc8eb470d95c09d"
[[package]]
name = "rustc-hash"

View File

@@ -6,7 +6,7 @@ edition = "2024"
[dependencies]
# tidy-alphabetical-start
punycode = "0.4.0"
rustc-demangle = "0.1.21"
rustc-demangle = "0.1.27"
rustc_abi = { path = "../rustc_abi" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }

View File

@@ -648,7 +648,10 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> {
p.push_ident(name.as_str());
match projection.term.kind() {
ty::TermKind::Ty(ty) => ty.print(p),
ty::TermKind::Const(c) => c.print(p),
ty::TermKind::Const(c) => {
p.push("K");
c.print(p)
}
}?;
}
ty::ExistentialPredicate::AutoTrait(def_id) => {

View File

@@ -857,7 +857,11 @@ Remaining primitives are encoded as a crate production, e.g. `C4f128`.
>
> <span id="dyn-trait">dyn-trait</span> → *[path]* {*[dyn-trait-assoc-binding]*}
>
> <span id="dyn-trait-assoc-binding">dyn-trait-assoc-binding</span> → `p` *[undisambiguated-identifier]* *[type]*
> <span id="dyn-trait-assoc-binding">dyn-trait-assoc-binding</span> → `p` *[undisambiguated-identifier]* *[type-or-const]*
>
> <span id="type-or-const">type-or-const</span> → \
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *[type]* \
> &nbsp;&nbsp; | `K` *[const]*
The tag `D` is followed by a *[dyn-bounds]* which encodes the trait bounds,
followed by a *[lifetime]* of the trait object lifetime bound.
@@ -867,11 +871,12 @@ Remaining primitives are encoded as a crate production, e.g. `C4f128`.
Each *[dyn-trait]* represents a trait bound, which consists of a *[path]* to the trait followed by zero or more *[dyn-trait-assoc-binding]* which list the associated types.
Each *[dyn-trait-assoc-binding]* consists of a character `p` followed a *[undisambiguated-identifier]* representing the associated binding name, and finally a *[type]*.
Each *[dyn-trait-assoc-binding]* consists of a character `p` followed a *[undisambiguated-identifier]* representing the associated binding name, and finally a *[type-or-const]*.
[dyn-bounds]: #dyn-bounds
[dyn-trait]: #dyn-trait
[dyn-trait-assoc-binding]: #dyn-trait-assoc-binding
[type-or-const]: #type-or-const
* A *[path]* to a named type.

View File

@@ -0,0 +1,28 @@
// Ensure that we can successfully mangle & demangle trait object types w/ assoc const bindings.
// FIXME(mgca): Legacy mangling still crashes:
// "finding type for [impl], encountered [crate root] with no parent"
//@ build-fail
//@ revisions: v0
//\@[legacy] compile-flags: -C symbol-mangling-version=legacy -Z unstable-options
//@ [v0] compile-flags: -C symbol-mangling-version=v0
//\@[legacy] normalize-stderr: "h[[:xdigit:]]{16}" -> "h[HASH]"
//@ [v0] normalize-stderr: "sym\[.*?\]" -> "sym[HASH]"
#![feature(min_generic_const_args, rustc_attrs)]
#![expect(incomplete_features)]
#![crate_name = "sym"]
trait Trait {
#[type_const]
const N: usize;
}
#[rustc_symbol_name]
//~^ ERROR symbol-name(_RMCs
//~| ERROR demangling(<dyn sym[
//~| ERROR demangling-alt(<dyn sym::Trait<N = 0>>)
impl dyn Trait<N = 0> {}
fn main() {}

View File

@@ -0,0 +1,20 @@
error: symbol-name(_RMCsCRATE_HASH_3symDNtB<REF>_5Traitp1NKj0_EL_)
--> $DIR/dyn-compat-symbol-mangling.rs:22:1
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling(<dyn sym[HASH]::Trait<N = 0usize>>)
--> $DIR/dyn-compat-symbol-mangling.rs:22:1
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: demangling-alt(<dyn sym::Trait<N = 0>>)
--> $DIR/dyn-compat-symbol-mangling.rs:22:1
|
LL | #[rustc_symbol_name]
| ^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors