@@ -946,73 +946,64 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
946946 }
947947
948948 fn print_const ( & mut self ) -> fmt:: Result {
949- parse ! ( self , push_depth) ;
950-
951- if self . eat ( b'B' ) {
952- self . print_backref ( Self :: print_const) ?;
953-
954- self . pop_depth ( ) ;
955- return Ok ( ( ) ) ;
956- }
957-
958- 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 . print ( "_" ) ?;
949+ let tag = parse ! ( self , next) ;
963950
964- self . pop_depth ( ) ;
965- return Ok ( ( ) ) ;
966- }
951+ parse ! ( self , push_depth) ;
967952
968- match ty_tag {
953+ match tag {
954+ // Placeholder.
955+ b'p' => self . print ( "_" ) ?,
969956 // Unsigned integer types.
970- b'h' | b't' | b'm' | b'y' | b'o' | b'j' => self . print_const_uint ( ) ?,
957+ b'h' | b't' | b'm' | b'y' | b'o' | b'j' => self . print_const_uint ( tag ) ?,
971958 // Signed integer types.
972- b'a' | b's' | b'l' | b'x' | b'n' | b'i' => self . print_const_int ( ) ?,
959+ b'a' | b's' | b'l' | b'x' | b'n' | b'i' => self . print_const_int ( tag ) ?,
973960 // Bool.
974961 b'b' => self . print_const_bool ( ) ?,
975962 // Char.
976963 b'c' => self . print_const_char ( ) ?,
977964
978- // This branch ought to be unreachable.
965+ b'B' => {
966+ self . print_backref ( Self :: print_const) ?;
967+ }
968+
979969 _ => invalid ! ( self ) ,
980970 } ;
981971
982- if let Some ( out) = & mut self . out {
983- if !out. alternate ( ) {
984- self . print ( ": " ) ?;
985- let ty = basic_type ( ty_tag) . unwrap ( ) ;
986- self . print ( ty) ?;
987- }
988- }
989-
990972 self . pop_depth ( ) ;
991973 Ok ( ( ) )
992974 }
993975
994- fn print_const_uint ( & mut self ) -> fmt:: Result {
976+ fn print_const_uint ( & mut self , ty_tag : u8 ) -> fmt:: Result {
995977 let hex = parse ! ( self , hex_nibbles) ;
996978
997979 // Print anything that doesn't fit in `u64` verbatim.
998980 if hex. len ( ) > 16 {
999981 self . print ( "0x" ) ?;
1000- return self . print ( hex) ;
982+ self . print ( hex) ?;
983+ } else {
984+ let mut v = 0 ;
985+ for c in hex. chars ( ) {
986+ v = ( v << 4 ) | ( c. to_digit ( 16 ) . unwrap ( ) as u64 ) ;
987+ }
988+ self . print ( v) ?;
1001989 }
1002990
1003- let mut v = 0 ;
1004- for c in hex. chars ( ) {
1005- v = ( v << 4 ) | ( c. to_digit ( 16 ) . unwrap ( ) as u64 ) ;
991+ if let Some ( out) = & mut self . out {
992+ if !out. alternate ( ) {
993+ let ty = basic_type ( ty_tag) . unwrap ( ) ;
994+ self . print ( ty) ?;
995+ }
1006996 }
1007- self . print ( v)
997+
998+ Ok ( ( ) )
1008999 }
10091000
1010- fn print_const_int ( & mut self ) -> fmt:: Result {
1001+ fn print_const_int ( & mut self , ty_tag : u8 ) -> fmt:: Result {
10111002 if self . eat ( b'n' ) {
10121003 self . print ( "-" ) ?;
10131004 }
10141005
1015- self . print_const_uint ( )
1006+ self . print_const_uint ( ty_tag )
10161007 }
10171008
10181009 fn print_const_bool ( & mut self ) -> fmt:: Result {
@@ -1073,12 +1064,12 @@ mod tests {
10731064 )
10741065 } ;
10751066 }
1076- macro_rules! t_const_typed {
1077- ( $mangled: expr, $value: expr, $value_ty : expr) => { {
1067+ macro_rules! t_const_suffixed {
1068+ ( $mangled: expr, $value: expr, $value_ty_suffix : expr) => { {
10781069 t_const!( $mangled, $value) ;
10791070 t!(
10801071 concat!( "_RIC0K" , $mangled, "E" ) ,
1081- concat!( "[0]::<" , $value, ": " , $value_ty , ">" )
1072+ concat!( "[0]::<" , $value, $value_ty_suffix , ">" )
10821073 ) ;
10831074 } } ;
10841075 }
@@ -1124,20 +1115,21 @@ mod tests {
11241115 "INtC8arrayvec8ArrayVechKj7b_E" ,
11251116 "arrayvec::ArrayVec<u8, 123>"
11261117 ) ;
1127- t_const_typed ! ( "j7b_" , "123" , "usize" ) ;
1118+ t_const_suffixed ! ( "j7b_" , "123" , "usize" ) ;
11281119 }
11291120
11301121 #[ test]
11311122 fn demangle_min_const_generics ( ) {
11321123 t_const ! ( "p" , "_" ) ;
1133- t_const_typed ! ( "hb_" , "11" , "u8" ) ;
1134- t_const_typed ! ( "s98_" , "152" , "i16" ) ;
1135- t_const_typed ! ( "anb_" , "-11" , "i8" ) ;
1136- t_const_typed ! ( "b0_" , "false" , "bool" ) ;
1137- t_const_typed ! ( "b1_" , "true" , "bool" ) ;
1138- t_const_typed ! ( "c76_" , "'v'" , "char" ) ;
1139- t_const_typed ! ( "ca_" , "'\\ n'" , "char" ) ;
1140- t_const_typed ! ( "c2202_" , "'∂'" , "char" ) ;
1124+ t_const_suffixed ! ( "hb_" , "11" , "u8" ) ;
1125+ t_const_suffixed ! ( "off00ff00ff00ff00ff_" , "0xff00ff00ff00ff00ff" , "u128" ) ;
1126+ t_const_suffixed ! ( "s98_" , "152" , "i16" ) ;
1127+ t_const_suffixed ! ( "anb_" , "-11" , "i8" ) ;
1128+ t_const ! ( "b0_" , "false" ) ;
1129+ t_const ! ( "b1_" , "true" ) ;
1130+ t_const ! ( "c76_" , "'v'" ) ;
1131+ t_const ! ( "ca_" , "'\\ n'" ) ;
1132+ t_const ! ( "c2202_" , "'∂'" ) ;
11411133 }
11421134
11431135 #[ test]
0 commit comments