Skip to content

Commit 8fa258c

Browse files
committed
v0: demangle ADT const values.
1 parent f85e369 commit 8fa258c

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/v0.rs

+43
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,33 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
11671167
}
11681168
self.print(")")?;
11691169
}
1170+
b'V' => {
1171+
open_brace_if_outside_expr(self)?;
1172+
self.print_path(true)?;
1173+
match parse!(self, next) {
1174+
b'U' => {}
1175+
b'T' => {
1176+
self.print("(")?;
1177+
self.print_sep_list(|this| this.print_const(true), ", ")?;
1178+
self.print(")")?;
1179+
}
1180+
b'S' => {
1181+
self.print(" { ")?;
1182+
self.print_sep_list(
1183+
|this| {
1184+
parse!(this, disambiguator);
1185+
let name = parse!(this, ident);
1186+
this.print(name)?;
1187+
this.print(": ")?;
1188+
this.print_const(true)
1189+
},
1190+
", ",
1191+
)?;
1192+
self.print(" }")?;
1193+
}
1194+
_ => invalid!(self),
1195+
}
1196+
}
11701197
b'B' => {
11711198
self.print_backref(|this| this.print_const(in_value))?;
11721199
}
@@ -1378,6 +1405,22 @@ mod tests {
13781405
);
13791406
}
13801407

1408+
#[test]
1409+
fn demangle_const_adt() {
1410+
t_const!(
1411+
"VNvINtNtC4core6option6OptionjE4NoneU",
1412+
"{core::option::Option::<usize>::None}"
1413+
);
1414+
t_const!(
1415+
"VNvINtNtC4core6option6OptionjE4SomeTj0_E",
1416+
"{core::option::Option::<usize>::Some(0)}"
1417+
);
1418+
t_const!(
1419+
"VNtC3foo3BarS1sRe616263_2chc78_5sliceRAh1_h2_h3_EE",
1420+
"{foo::Bar { s: \"abc\", ch: 'x', slice: &[1, 2, 3] }}"
1421+
);
1422+
}
1423+
13811424
#[test]
13821425
fn demangle_exponential_explosion() {
13831426
// NOTE(eddyb) because of the prefix added by `t_nohash_type!` is

0 commit comments

Comments
 (0)