@@ -2595,9 +2595,7 @@ fn num_decimal_digits(num: usize) -> usize {
25952595
25962596// We replace some characters so the CLI output is always consistent and underlines aligned.
25972597// Keep the following list in sync with `rustc_span::char_width`.
2598- // ATTENTION: keep lexicografically sorted so that the binary search will work
25992598const OUTPUT_REPLACEMENTS : & [ ( char , & str ) ] = & [
2600- // tidy-alphabetical-start
26012599 // In terminals without Unicode support the following will be garbled, but in *all* terminals
26022600 // the underlying codepoint will be as well. We could gate this replacement behind a "unicode
26032601 // support" gate.
@@ -2610,7 +2608,7 @@ const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[
26102608 ( '\u{0006}' , "␆" ) ,
26112609 ( '\u{0007}' , "␇" ) ,
26122610 ( '\u{0008}' , "␈" ) ,
2613- ( '\u{0009} ' , " " ) , // We do our own tab replacement
2611+ ( '\t ' , " " ) , // We do our own tab replacement
26142612 ( '\u{000b}' , "␋" ) ,
26152613 ( '\u{000c}' , "␌" ) ,
26162614 ( '\u{000d}' , "␍" ) ,
@@ -2643,13 +2641,23 @@ const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[
26432641 ( '\u{2067}' , "�" ) ,
26442642 ( '\u{2068}' , "�" ) ,
26452643 ( '\u{2069}' , "�" ) ,
2646- // tidy-alphabetical-end
26472644] ;
26482645
26492646fn normalize_whitespace ( s : & str ) -> String {
2650- // Scan the input string for a character in the ordered table above. If it's present, replace
2651- // it with it's alternative string (it can be more than 1 char!). Otherwise, retain the input
2652- // char. At the end, allocate all chars into a string in one operation.
2647+ const {
2648+ let mut i = 1 ;
2649+ while i < OUTPUT_REPLACEMENTS . len ( ) {
2650+ assert ! (
2651+ OUTPUT_REPLACEMENTS [ i - 1 ] . 0 < OUTPUT_REPLACEMENTS [ i] . 0 ,
2652+ "The OUTPUT_REPLACEMENTS array must be sorted (for binary search to work) \
2653+ and must contain no duplicate entries"
2654+ ) ;
2655+ i += 1 ;
2656+ }
2657+ }
2658+ // Scan the input string for a character in the ordered table above.
2659+ // If it's present, replace it with its alternative string (it can be more than 1 char!).
2660+ // Otherwise, retain the input char.
26532661 s. chars ( ) . fold ( String :: with_capacity ( s. len ( ) ) , |mut s, c| {
26542662 match OUTPUT_REPLACEMENTS . binary_search_by_key ( & c, |( k, _) | * k) {
26552663 Ok ( i) => s. push_str ( OUTPUT_REPLACEMENTS [ i] . 1 ) ,
0 commit comments