Skip to content

Demangle using fixed-length disambiguators - #94

Open
teor2345 wants to merge 2 commits into
rust-lang:mainfrom
teor2345:short-crate-hash
Open

Demangle using fixed-length disambiguators#94
teor2345 wants to merge 2 commits into
rust-lang:mainfrom
teor2345:short-crate-hash

Conversation

@teor2345

@teor2345 teor2345 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Most UI tests expect a 16-character disambiguator, but rustc-demangle omits leading zeroes.
This can cause test failures on ~1/16 of the changes to demangling tests.

For example: rust-lang/rust#160050 (comment)

This PR adds a Disambiguator wrapper type, so it is impossible to format it incorrectly.

I used https://www.dcode.fr/base62-encoding to generate the encoded examples, you need to select the second alphabet (lowercase first).

@teor2345 teor2345 changed the title Demangle fixed-length disambiguators Demangle using fixed-length disambiguators Jul 31, 2026
Comment thread src/v0.rs
let hex_len = self.0.bit_width().div_ceil(4).max(1);
let fill_len = 16 - (hex_len as usize);
out.write_str(&Self::MAX_HEX_FILL[0..fill_len])?;
fmt::LowerHex::fmt(&self.0, out)

@bjorn3 bjorn3 Jul 31, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write!(out, "{:016x}", self.0) would work too, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this is core-only code:

macro_rules! write {
($($ignored:tt)*) => {
compile_error!(
"use `self.print(value)` or `fmt::Trait::fmt(&value, self.out)`, \
instead of `write!(self.out, \"{...}\", value)`"
)
};
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write!() is in core. I don't know if the reason given for avoiding write!() in #50 is still fully valid given that we had a change to the fmt implementation since:

The second commit is mostly stylistic, trying to enforce a pattern of "not using write! in demangling logic", and only using fmt::Trait::fmt(&value, self.out) - which I'm guessing we do want (for performance reasons?).

In any case I guess the current code is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants