Skip to content

Commit 7551efa

Browse files
authored
Elide the type when the const value is a placeholder p (#40)
1 parent 6e407b5 commit 7551efa

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

src/v0.rs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,16 @@ impl<'s> Parser<'s> {
548548
}
549549

550550
let ty_tag = self.next()?;
551+
552+
if ty_tag == b'p' {
553+
// We don't encode the type if the value is a placeholder.
554+
return Ok(());
555+
}
556+
551557
if !supported_const_generic_type(ty_tag) {
552558
return Err(Invalid);
553559
}
554560

555-
if self.eat(b'p') {
556-
return Ok(());
557-
}
558561
// Negation on signed integers.
559562
if let b'a' | b's' | b'l' | b'x' | b'n' | b'i' = ty_tag {
560563
let _ = self.eat(b'n');
@@ -953,27 +956,30 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
953956
}
954957

955958
let ty_tag = parse!(self, next);
959+
960+
if ty_tag == b'p' {
961+
// We don't encode the type if the value is a placeholder.
962+
self.out.write_str("_")?;
963+
return Ok(());
964+
}
965+
956966
if !supported_const_generic_type(ty_tag) {
957967
invalid!(self);
958968
}
959969

960-
if self.eat(b'p') {
961-
self.out.write_str("_")?;
962-
} else {
963-
match ty_tag {
964-
// Unsigned integer types.
965-
b'h' | b't' | b'm' | b'y' | b'o' | b'j' => self.print_const_uint()?,
966-
// Signed integer types.
967-
b'a' | b's' | b'l' | b'x' | b'n' | b'i' => self.print_const_int()?,
968-
// Bool.
969-
b'b' => self.print_const_bool()?,
970-
// Char.
971-
b'c' => self.print_const_char()?,
972-
973-
// This branch ought to be unreachable.
974-
_ => invalid!(self),
975-
};
976-
}
970+
match ty_tag {
971+
// Unsigned integer types.
972+
b'h' | b't' | b'm' | b'y' | b'o' | b'j' => self.print_const_uint()?,
973+
// Signed integer types.
974+
b'a' | b's' | b'l' | b'x' | b'n' | b'i' => self.print_const_int()?,
975+
// Bool.
976+
b'b' => self.print_const_bool()?,
977+
// Char.
978+
b'c' => self.print_const_char()?,
979+
980+
// This branch ought to be unreachable.
981+
_ => invalid!(self),
982+
};
977983

978984
if !self.out.alternate() {
979985
self.out.write_str(": ")?;
@@ -1118,6 +1124,10 @@ mod tests {
11181124
"_RMCs4fqI2P2rA04_13const_genericINtB0_4CharKc2202_E",
11191125
"<const_generic::Char<'∂'>>"
11201126
);
1127+
t_nohash!(
1128+
"_RNvNvMCs4fqI2P2rA04_13const_genericINtB4_3FooKpE3foo3FOO",
1129+
"<const_generic::Foo<_>>::foo::FOO"
1130+
);
11211131
}
11221132

11231133
#[test]

0 commit comments

Comments
 (0)