Skip to content

Commit

Permalink
v0: demangle ADT const values.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Aug 10, 2021
1 parent f85e369 commit 8fa258c
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,33 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
}
self.print(")")?;
}
b'V' => {
open_brace_if_outside_expr(self)?;
self.print_path(true)?;
match parse!(self, next) {
b'U' => {}
b'T' => {
self.print("(")?;
self.print_sep_list(|this| this.print_const(true), ", ")?;
self.print(")")?;
}
b'S' => {
self.print(" { ")?;
self.print_sep_list(
|this| {
parse!(this, disambiguator);
let name = parse!(this, ident);
this.print(name)?;
this.print(": ")?;
this.print_const(true)
},
", ",
)?;
self.print(" }")?;
}
_ => invalid!(self),
}
}
b'B' => {
self.print_backref(|this| this.print_const(in_value))?;
}
Expand Down Expand Up @@ -1378,6 +1405,22 @@ mod tests {
);
}

#[test]
fn demangle_const_adt() {
t_const!(
"VNvINtNtC4core6option6OptionjE4NoneU",
"{core::option::Option::<usize>::None}"
);
t_const!(
"VNvINtNtC4core6option6OptionjE4SomeTj0_E",
"{core::option::Option::<usize>::Some(0)}"
);
t_const!(
"VNtC3foo3BarS1sRe616263_2chc78_5sliceRAh1_h2_h3_EE",
"{foo::Bar { s: \"abc\", ch: 'x', slice: &[1, 2, 3] }}"
);
}

#[test]
fn demangle_exponential_explosion() {
// NOTE(eddyb) because of the prefix added by `t_nohash_type!` is
Expand Down

0 comments on commit 8fa258c

Please sign in to comment.