Skip to content

Add new v0 demangling tags for pattern types #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,11 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
b'B' => {
self.print_backref(Self::print_type)?;
}
b'W' => {
self.print_type()?;
self.print(" is ")?;
self.print_pat()?;
}
_ => {
// Go back to the tag, so `print_path` also sees it.
let _ = self.parser.as_mut().map(|p| p.next -= 1);
Expand Down Expand Up @@ -1079,6 +1084,36 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
Ok(())
}

fn print_pat(&mut self) -> fmt::Result {
let tag = parse!(self, next);

match tag {
b'R' => {
self.print_const(false)?;
self.print("..=")?;
self.print_const(false)?;
}
b'O' => {
parse!(self, push_depth);
self.print_pat()?;
while !self.eat(b'E') {
// May have reached the end of the string,
// avoid going into an endless loop.
if self.parser.is_err() {
invalid!(self)
}
self.print(" | ")?;
self.print_pat()?;
}
self.pop_depth();
}
b'N' => self.print("!null")?,
_ => invalid!(self),
}

Ok(())
}

fn print_const(&mut self, in_value: bool) -> fmt::Result {
let tag = parse!(self, next);

Expand Down Expand Up @@ -1315,6 +1350,13 @@ mod tests {
);
}

#[test]
fn demangle_pat_ty() {
t_nohash_type!("WmRm1_m9_", "u32 is 1..=9");
t_nohash_type!("WmORm1_m2_Rm5_m6_E", "u32 is 1..=2 | 5..=6");
assert!(::v0::demangle("_RMC0WmORm1_m2_Rm5_m6_").is_err());
}

#[test]
fn demangle_const_generics_preview() {
// NOTE(eddyb) this was hand-written, before rustc had working
Expand Down