@@ -1009,6 +1009,11 @@ mod tests {
10091009 assert_eq!( format!( "{:#}" , :: demangle( $a) ) , $b) ;
10101010 } )
10111011 }
1012+ macro_rules! t_nohash_type {
1013+ ( $a: expr, $b: expr) => (
1014+ t_nohash!( concat!( "_RMC0" , $a) , concat!( "<" , $b, ">" ) )
1015+ )
1016+ }
10121017
10131018 #[ test]
10141019 fn demangle_utf8_idents ( ) {
@@ -1042,9 +1047,25 @@ mod tests {
10421047 fn demangle_const_generics ( ) {
10431048 // NOTE(eddyb) this was hand-written, before rustc had working
10441049 // const generics support (but the mangling format did include them).
1045- t_nohash ! (
1046- "_RNvINtC8arrayvec8ArrayVechKj7b_E3new" ,
1047- "arrayvec::ArrayVec::<u8, 123>::new"
1050+ t_nohash_type ! (
1051+ "INtC8arrayvec8ArrayVechKj7b_E" ,
1052+ "arrayvec::ArrayVec<u8, 123>"
1053+ ) ;
1054+ }
1055+
1056+ #[ test]
1057+ fn demangle_exponential_explosion ( ) {
1058+ // NOTE(eddyb) because of the prefix added by `t_nohash_type!` is
1059+ // 3 bytes long, `B2_` refers to the start of the type, not `B_`.
1060+ // 6 backrefs (`B8_E` through `B3_E`) result in 2^6 = 64 copies of `_`.
1061+ // Also, because the `p` (`_`) type is after all of the starts of the
1062+ // backrefs, it can be replaced with any other type, independently.
1063+ t_nohash_type ! (
1064+ concat!( "TTTTTT" , "p" , "B8_E" , "B7_E" , "B6_E" , "B5_E" , "B4_E" , "B3_E" ) ,
1065+ "((((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _)))), \
1066+ ((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _))))), \
1067+ (((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _)))), \
1068+ ((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _))))))"
10481069 ) ;
10491070 }
10501071}
0 commit comments