Skip to content
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
46 changes: 20 additions & 26 deletions src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ pub fn demangle(s: &str) -> Result<(Demangle, &str), Invalid> {
Ok((Demangle { inner }, &parser.sym[parser.next..]))
}

fn supported_const_generic_type(ty_tag: u8) -> bool {
match ty_tag {
// Unsigned integer types.
b'h' | b't' | b'm' | b'y' | b'o' | b'j' |
// Signed integer types.
b'a' | b's' | b'l' | b'x' | b'n' | b'i' |
// Bool.
b'b' |
// Char.
b'c' => true,

_ => false,
}
}

impl<'s> Display for Demangle<'s> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut printer = Printer {
Expand Down Expand Up @@ -554,14 +539,23 @@ impl<'s> Parser<'s> {
return Ok(());
}

if !supported_const_generic_type(ty_tag) {
return Err(Invalid);
}
match ty_tag {
// Unsigned integer types.
b'h' | b't' | b'm' | b'y' | b'o' | b'j' |
// Bool.
b'b' |
// Char.
b'c' => {}

// Negation on signed integers.
if let b'a' | b's' | b'l' | b'x' | b'n' | b'i' = ty_tag {
let _ = self.eat(b'n');
// Signed integer types.
b'a' | b's' | b'l' | b'x' | b'n' | b'i' => {
// Negation on signed integers.
let _ = self.eat(b'n');
}

_ => return Err(Invalid),
}

self.hex_nibbles()?;
Ok(())
}
Expand Down Expand Up @@ -963,10 +957,6 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
return Ok(());
}

if !supported_const_generic_type(ty_tag) {
invalid!(self);
}

match ty_tag {
// Unsigned integer types.
b'h' | b't' | b'm' | b'y' | b'o' | b'j' => self.print_const_uint()?,
Expand Down Expand Up @@ -1035,7 +1025,7 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
v = (v << 4) | (c.to_digit(16).unwrap() as u32);
}
if let Some(c) = char::from_u32(v) {
write!(self.out, "'{}'", c)
write!(self.out, "{:?}", c)
} else {
invalid!(self)
}
Expand Down Expand Up @@ -1120,6 +1110,10 @@ mod tests {
"_RMCs4fqI2P2rA04_13const_genericINtB0_4CharKc76_E",
"<const_generic::Char<'v'>>"
);
t_nohash!(
"_RMCs4fqI2P2rA04_13const_genericINtB0_4CharKca_E",
"<const_generic::Char<'\\n'>>"
);
t_nohash!(
"_RMCs4fqI2P2rA04_13const_genericINtB0_4CharKc2202_E",
"<const_generic::Char<'∂'>>"
Expand Down