Skip to content

Commit 2fb651d

Browse files
committed
Add new v0 demangling tags for pattern types
1 parent 83f1bbd commit 2fb651d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/v0.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,11 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
10181018
b'B' => {
10191019
self.print_backref(Self::print_type)?;
10201020
}
1021+
b'W' => {
1022+
self.print_type()?;
1023+
self.print(" is ")?;
1024+
self.print_pat()?;
1025+
}
10211026
_ => {
10221027
// Go back to the tag, so `print_path` also sees it.
10231028
let _ = self.parser.as_mut().map(|p| p.next -= 1);
@@ -1079,6 +1084,36 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
10791084
Ok(())
10801085
}
10811086

1087+
fn print_pat(&mut self) -> fmt::Result {
1088+
let tag = parse!(self, next);
1089+
1090+
match tag {
1091+
b'R' => {
1092+
self.print_const(false)?;
1093+
self.print("..=")?;
1094+
self.print_const(false)?;
1095+
}
1096+
b'O' => {
1097+
parse!(self, push_depth);
1098+
self.print_pat()?;
1099+
while !self.eat(b'E') {
1100+
// May have reached the end of the string,
1101+
// avoid going into an endless loop.
1102+
if self.parser.is_err() {
1103+
invalid!(self)
1104+
}
1105+
self.print(" | ")?;
1106+
self.print_pat()?;
1107+
}
1108+
self.pop_depth();
1109+
}
1110+
b'N' => self.print("!null")?,
1111+
_ => invalid!(self),
1112+
}
1113+
1114+
Ok(())
1115+
}
1116+
10821117
fn print_const(&mut self, in_value: bool) -> fmt::Result {
10831118
let tag = parse!(self, next);
10841119

@@ -1315,6 +1350,13 @@ mod tests {
13151350
);
13161351
}
13171352

1353+
#[test]
1354+
fn demangle_pat_ty() {
1355+
t_nohash_type!("WmRm1_m9_", "u32 is 1..=9");
1356+
t_nohash_type!("WmORm1_m2_Rm5_m6_E", "u32 is 1..=2 | 5..=6");
1357+
assert!(::v0::demangle("_RMC0WmORm1_m2_Rm5_m6_").is_err());
1358+
}
1359+
13181360
#[test]
13191361
fn demangle_const_generics_preview() {
13201362
// NOTE(eddyb) this was hand-written, before rustc had working

0 commit comments

Comments
 (0)