@@ -978,23 +978,42 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
978978 parse ! ( self , push_depth) ;
979979
980980 match tag {
981- // Placeholder.
982981 b'p' => self . print ( "_" ) ?,
983- // Unsigned integer types.
982+
983+ // Primitive leaves with hex-encoded values (see `basic_type`).
984984 b'h' | b't' | b'm' | b'y' | b'o' | b'j' => self . print_const_uint ( tag) ?,
985- // Signed integer types.
986- b'a' | b's' | b'l' | b'x' | b'n' | b'i' => self . print_const_int ( tag) ?,
987- // Bool.
988- b'b' => self . print_const_bool ( ) ?,
989- // Char.
990- b'c' => self . print_const_char ( ) ?,
985+ b'a' | b's' | b'l' | b'x' | b'n' | b'i' => {
986+ if self . eat ( b'n' ) {
987+ self . print ( "-" ) ?;
988+ }
989+
990+ self . print_const_uint ( tag) ?;
991+ }
992+ b'b' => match parse ! ( self , hex_nibbles) . try_parse_uint ( ) {
993+ Some ( 0 ) => self . print ( "false" ) ?,
994+ Some ( 1 ) => self . print ( "true" ) ?,
995+ _ => invalid ! ( self ) ,
996+ } ,
997+ b'c' => {
998+ let valid_char = parse ! ( self , hex_nibbles)
999+ . try_parse_uint ( )
1000+ . and_then ( |v| u32:: try_from ( v) . ok ( ) )
1001+ . and_then ( char:: from_u32) ;
1002+ match valid_char {
1003+ Some ( c) => {
1004+ if let Some ( out) = & mut self . out {
1005+ fmt:: Debug :: fmt ( & c, out) ?;
1006+ }
1007+ }
1008+ None => invalid ! ( self ) ,
1009+ }
1010+ }
9911011
9921012 b'B' => {
9931013 self . print_backref ( Self :: print_const) ?;
9941014 }
995-
9961015 _ => invalid ! ( self ) ,
997- } ;
1016+ }
9981017
9991018 self . pop_depth ( ) ;
10001019 Ok ( ( ) )
@@ -1022,38 +1041,6 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
10221041
10231042 Ok ( ( ) )
10241043 }
1025-
1026- fn print_const_int ( & mut self , ty_tag : u8 ) -> fmt:: Result {
1027- if self . eat ( b'n' ) {
1028- self . print ( "-" ) ?;
1029- }
1030-
1031- self . print_const_uint ( ty_tag)
1032- }
1033-
1034- fn print_const_bool ( & mut self ) -> fmt:: Result {
1035- match parse ! ( self , hex_nibbles) . try_parse_uint ( ) {
1036- Some ( 0 ) => self . print ( "false" ) ,
1037- Some ( 1 ) => self . print ( "true" ) ,
1038- _ => invalid ! ( self ) ,
1039- }
1040- }
1041-
1042- fn print_const_char ( & mut self ) -> fmt:: Result {
1043- match parse ! ( self , hex_nibbles)
1044- . try_parse_uint ( )
1045- . and_then ( |v| u32:: try_from ( v) . ok ( ) )
1046- . and_then ( char:: from_u32)
1047- {
1048- Some ( c) => {
1049- if let Some ( out) = & mut self . out {
1050- fmt:: Debug :: fmt ( & c, out) ?;
1051- }
1052- Ok ( ( ) )
1053- }
1054- None => invalid ! ( self ) ,
1055- }
1056- }
10571044}
10581045
10591046#[ cfg( test) ]
0 commit comments