@@ -946,73 +946,64 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
946
946
}
947
947
948
948
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) ;
963
950
964
- self . pop_depth ( ) ;
965
- return Ok ( ( ) ) ;
966
- }
951
+ parse ! ( self , push_depth) ;
967
952
968
- match ty_tag {
953
+ match tag {
954
+ // Placeholder.
955
+ b'p' => self . print ( "_" ) ?,
969
956
// 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 ) ?,
971
958
// 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 ) ?,
973
960
// Bool.
974
961
b'b' => self . print_const_bool ( ) ?,
975
962
// Char.
976
963
b'c' => self . print_const_char ( ) ?,
977
964
978
- // This branch ought to be unreachable.
965
+ b'B' => {
966
+ self . print_backref ( Self :: print_const) ?;
967
+ }
968
+
979
969
_ => invalid ! ( self ) ,
980
970
} ;
981
971
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
-
990
972
self . pop_depth ( ) ;
991
973
Ok ( ( ) )
992
974
}
993
975
994
- fn print_const_uint ( & mut self ) -> fmt:: Result {
976
+ fn print_const_uint ( & mut self , ty_tag : u8 ) -> fmt:: Result {
995
977
let hex = parse ! ( self , hex_nibbles) ;
996
978
997
979
// Print anything that doesn't fit in `u64` verbatim.
998
980
if hex. len ( ) > 16 {
999
981
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) ?;
1001
989
}
1002
990
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
+ }
1006
996
}
1007
- self . print ( v)
997
+
998
+ Ok ( ( ) )
1008
999
}
1009
1000
1010
- fn print_const_int ( & mut self ) -> fmt:: Result {
1001
+ fn print_const_int ( & mut self , ty_tag : u8 ) -> fmt:: Result {
1011
1002
if self . eat ( b'n' ) {
1012
1003
self . print ( "-" ) ?;
1013
1004
}
1014
1005
1015
- self . print_const_uint ( )
1006
+ self . print_const_uint ( ty_tag )
1016
1007
}
1017
1008
1018
1009
fn print_const_bool ( & mut self ) -> fmt:: Result {
@@ -1073,12 +1064,12 @@ mod tests {
1073
1064
)
1074
1065
} ;
1075
1066
}
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) => { {
1078
1069
t_const!( $mangled, $value) ;
1079
1070
t!(
1080
1071
concat!( "_RIC0K" , $mangled, "E" ) ,
1081
- concat!( "[0]::<" , $value, ": " , $value_ty , ">" )
1072
+ concat!( "[0]::<" , $value, $value_ty_suffix , ">" )
1082
1073
) ;
1083
1074
} } ;
1084
1075
}
@@ -1124,20 +1115,21 @@ mod tests {
1124
1115
"INtC8arrayvec8ArrayVechKj7b_E" ,
1125
1116
"arrayvec::ArrayVec<u8, 123>"
1126
1117
) ;
1127
- t_const_typed ! ( "j7b_" , "123" , "usize" ) ;
1118
+ t_const_suffixed ! ( "j7b_" , "123" , "usize" ) ;
1128
1119
}
1129
1120
1130
1121
#[ test]
1131
1122
fn demangle_min_const_generics ( ) {
1132
1123
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_" , "'∂'" ) ;
1141
1133
}
1142
1134
1143
1135
#[ test]
0 commit comments