Skip to content

Commit

Permalink
Elide the type when the const value is a placeholder p (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor authored Oct 7, 2020
1 parent 6e407b5 commit 7551efa
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,13 +548,16 @@ impl<'s> Parser<'s> {
}

let ty_tag = self.next()?;

if ty_tag == b'p' {
// We don't encode the type if the value is a placeholder.
return Ok(());
}

if !supported_const_generic_type(ty_tag) {
return Err(Invalid);
}

if self.eat(b'p') {
return Ok(());
}
// 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');
Expand Down Expand Up @@ -953,27 +956,30 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
}

let ty_tag = parse!(self, next);

if ty_tag == b'p' {
// We don't encode the type if the value is a placeholder.
self.out.write_str("_")?;
return Ok(());
}

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

if self.eat(b'p') {
self.out.write_str("_")?;
} else {
match ty_tag {
// Unsigned integer types.
b'h' | b't' | b'm' | b'y' | b'o' | b'j' => self.print_const_uint()?,
// Signed integer types.
b'a' | b's' | b'l' | b'x' | b'n' | b'i' => self.print_const_int()?,
// Bool.
b'b' => self.print_const_bool()?,
// Char.
b'c' => self.print_const_char()?,

// This branch ought to be unreachable.
_ => invalid!(self),
};
}
match ty_tag {
// Unsigned integer types.
b'h' | b't' | b'm' | b'y' | b'o' | b'j' => self.print_const_uint()?,
// Signed integer types.
b'a' | b's' | b'l' | b'x' | b'n' | b'i' => self.print_const_int()?,
// Bool.
b'b' => self.print_const_bool()?,
// Char.
b'c' => self.print_const_char()?,

// This branch ought to be unreachable.
_ => invalid!(self),
};

if !self.out.alternate() {
self.out.write_str(": ")?;
Expand Down Expand Up @@ -1118,6 +1124,10 @@ mod tests {
"_RMCs4fqI2P2rA04_13const_genericINtB0_4CharKc2202_E",
"<const_generic::Char<'∂'>>"
);
t_nohash!(
"_RNvNvMCs4fqI2P2rA04_13const_genericINtB4_3FooKpE3foo3FOO",
"<const_generic::Foo<_>>::foo::FOO"
);
}

#[test]
Expand Down

0 comments on commit 7551efa

Please sign in to comment.