@@ -2558,66 +2558,62 @@ fn num_decimal_digits(num: usize) -> usize {
25582558}
25592559
25602560// We replace some characters so the CLI output is always consistent and underlines aligned.
2561- // Keep the following list in sync with `rustc_span::char_width`.
2562- // ATTENTION: keep lexicografically sorted so that the binary search will work
2563- const OUTPUT_REPLACEMENTS : & [ ( char , & str ) ] = & [
2564- // tidy-alphabetical-start
2561+ const OUTPUT_REPLACEMENTS : phf:: Map < char , & ' static str > = phf:: phf_map![
25652562 // In terminals without Unicode support the following will be garbled, but in *all* terminals
25662563 // the underlying codepoint will be as well. We could gate this replacement behind a "unicode
25672564 // support" gate.
2568- ( '\0' , "␀" ) ,
2569- ( '\u{0001}' , "␁" ) ,
2570- ( '\u{0002}' , "␂" ) ,
2571- ( '\u{0003}' , "␃" ) ,
2572- ( '\u{0004}' , "␄" ) ,
2573- ( '\u{0005}' , "␅" ) ,
2574- ( '\u{0006}' , "␆" ) ,
2575- ( '\u{0007}' , "␇" ) ,
2576- ( '\u{0008}' , "␈" ) ,
2577- ( '\u{0009}' , " " ) , // We do our own tab replacement
2578- ( '\u{000b}' , "␋" ) ,
2579- ( '\u{000c}' , "␌" ) ,
2580- ( '\u{000d}' , "␍" ) ,
2581- ( '\u{000e}' , "␎" ) ,
2582- ( '\u{000f}' , "␏" ) ,
2583- ( '\u{0010}' , "␐" ) ,
2584- ( '\u{0011}' , "␑" ) ,
2585- ( '\u{0012}' , "␒" ) ,
2586- ( '\u{0013}' , "␓" ) ,
2587- ( '\u{0014}' , "␔" ) ,
2588- ( '\u{0015}' , "␕" ) ,
2589- ( '\u{0016}' , "␖" ) ,
2590- ( '\u{0017}' , "␗" ) ,
2591- ( '\u{0018}' , "␘" ) ,
2592- ( '\u{0019}' , "␙" ) ,
2593- ( '\u{001a}' , "␚" ) ,
2594- ( '\u{001b}' , "␛" ) ,
2595- ( '\u{001c}' , "␜" ) ,
2596- ( '\u{001d}' , "␝" ) ,
2597- ( '\u{001e}' , "␞" ) ,
2598- ( '\u{001f}' , "␟" ) ,
2599- ( '\u{007f}' , "␡" ) ,
2600- ( '\u{200d}' , "" ) , // Replace ZWJ for consistent terminal output of grapheme clusters.
2601- ( '\u{202a}' , "�" ) , // The following unicode text flow control characters are inconsistently
2602- ( '\u{202b}' , "�" ) , // supported across CLIs and can cause confusion due to the bytes on disk
2603- ( '\u{202c}' , "�" ) , // not corresponding to the visible source code, so we replace them always.
2604- ( '\u{202d}' , "�" ) ,
2605- ( '\u{202e}' , "�" ) ,
2606- ( '\u{2066}' , "�" ) ,
2607- ( '\u{2067}' , "�" ) ,
2608- ( '\u{2068}' , "�" ) ,
2609- ( '\u{2069}' , "�" ) ,
2610- // tidy-alphabetical-end
2565+ '\0' => "␀" ,
2566+ '\t' => " " , // We do our own tab replacement
2567+ '\r' => "␍" ,
2568+ '\u{0001}' => "␁" ,
2569+ '\u{0002}' => "␂" ,
2570+ '\u{0003}' => "␃" ,
2571+ '\u{0004}' => "␄" ,
2572+ '\u{0005}' => "␅" ,
2573+ '\u{0006}' => "␆" ,
2574+ '\u{0007}' => "␇" ,
2575+ '\u{0008}' => "␈" ,
2576+ '\u{000b}' => "␋" ,
2577+ '\u{000c}' => "␌" ,
2578+ '\u{000e}' => "␎" ,
2579+ '\u{000f}' => "␏" ,
2580+ '\u{0010}' => "␐" ,
2581+ '\u{0011}' => "␑" ,
2582+ '\u{0012}' => "␒" ,
2583+ '\u{0013}' => "␓" ,
2584+ '\u{0014}' => "␔" ,
2585+ '\u{0015}' => "␕" ,
2586+ '\u{0016}' => "␖" ,
2587+ '\u{0017}' => "␗" ,
2588+ '\u{0018}' => "␘" ,
2589+ '\u{0019}' => "␙" ,
2590+ '\u{001a}' => "␚" ,
2591+ '\u{001b}' => "␛" ,
2592+ '\u{001c}' => "␜" ,
2593+ '\u{001d}' => "␝" ,
2594+ '\u{001e}' => "␞" ,
2595+ '\u{001f}' => "␟" ,
2596+ '\u{007f}' => "␡" ,
2597+ '\u{200d}' => "" , // Replace ZWJ for consistent terminal output of grapheme clusters.
2598+ '\u{202a}' => "�" , // The following unicode text flow control characters are inconsistently
2599+ '\u{202b}' => "�" , // supported across CLIs and can cause confusion due to the bytes on disk
2600+ '\u{202c}' => "�" , // not corresponding to the visible source code, so we replace them always.
2601+ '\u{202d}' => "�" ,
2602+ '\u{202e}' => "�" ,
2603+ '\u{2066}' => "�" ,
2604+ '\u{2067}' => "�" ,
2605+ '\u{2068}' => "�" ,
2606+ '\u{2069}' => "�" ,
26112607] ;
26122608
26132609fn normalize_whitespace ( s : & str ) -> String {
26142610 // Scan the input string for a character in the ordered table above. If it's present, replace
26152611 // it with it's alternative string (it can be more than 1 char!). Otherwise, retain the input
26162612 // char. At the end, allocate all chars into a string in one operation.
26172613 s. chars ( ) . fold ( String :: with_capacity ( s. len ( ) ) , |mut s, c| {
2618- match OUTPUT_REPLACEMENTS . binary_search_by_key ( & c, | ( k , _ ) | * k ) {
2619- Ok ( i ) => s. push_str ( OUTPUT_REPLACEMENTS [ i ] . 1 ) ,
2620- _ => s. push ( c) ,
2614+ match OUTPUT_REPLACEMENTS . get ( & c) {
2615+ Some ( r ) => s. push_str ( r ) ,
2616+ None => s. push ( c) ,
26212617 }
26222618 s
26232619 } )
0 commit comments