@@ -44,7 +44,7 @@ use std::io::{BufWriter, Write};
44
44
use std:: ops:: Deref ;
45
45
use std:: path:: { Path , PathBuf } ;
46
46
use std:: process:: { ExitStatus , Output , Stdio } ;
47
- use std:: { ascii , char , env, fmt, fs, io, mem, str} ;
47
+ use std:: { env, fmt, fs, io, mem, str} ;
48
48
49
49
pub fn ensure_removed ( diag_handler : & Handler , path : & Path ) {
50
50
if let Err ( e) = fs:: remove_file ( path) {
@@ -552,14 +552,6 @@ fn link_staticlib<'a>(
552
552
Ok ( ( ) )
553
553
}
554
554
555
- fn escape_stdout_stderr_string ( s : & [ u8 ] ) -> String {
556
- str:: from_utf8 ( s) . map ( |s| s. to_owned ( ) ) . unwrap_or_else ( |_| {
557
- let mut x = "Non-UTF-8 output: " . to_string ( ) ;
558
- x. extend ( s. iter ( ) . flat_map ( |& b| ascii:: escape_default ( b) ) . map ( char:: from) ) ;
559
- x
560
- } )
561
- }
562
-
563
555
/// Use `thorin` (rust implementation of a dwarf packaging utility) to link DWARF objects into a
564
556
/// DWARF package.
565
557
fn link_dwarf_object < ' a > (
@@ -866,7 +858,7 @@ fn link_natively<'a>(
866
858
if !prog. status . success ( ) {
867
859
let mut output = prog. stderr . clone ( ) ;
868
860
output. extend_from_slice ( & prog. stdout ) ;
869
- let escaped_output = escape_stdout_stderr_string ( & output) ;
861
+ let escaped_output = escape_string ( & output) ;
870
862
let mut err = sess. struct_err ( & format ! (
871
863
"linking with `{}` failed: {}" ,
872
864
linker_path. display( ) ,
@@ -934,8 +926,8 @@ fn link_natively<'a>(
934
926
935
927
sess. abort_if_errors ( ) ;
936
928
}
937
- info ! ( "linker stderr:\n {}" , escape_stdout_stderr_string ( & prog. stderr) ) ;
938
- info ! ( "linker stdout:\n {}" , escape_stdout_stderr_string ( & prog. stdout) ) ;
929
+ info ! ( "linker stderr:\n {}" , escape_string ( & prog. stderr) ) ;
930
+ info ! ( "linker stdout:\n {}" , escape_string ( & prog. stdout) ) ;
939
931
}
940
932
Err ( e) => {
941
933
let linker_not_found = e. kind ( ) == io:: ErrorKind :: NotFound ;
@@ -1065,11 +1057,10 @@ fn strip_symbols_in_osx<'a>(sess: &'a Session, out_filename: &Path, option: Opti
1065
1057
}
1066
1058
1067
1059
fn escape_string ( s : & [ u8 ] ) -> String {
1068
- str:: from_utf8 ( s) . map ( |s| s. to_owned ( ) ) . unwrap_or_else ( |_| {
1069
- let mut x = "Non-UTF-8 output: " . to_string ( ) ;
1070
- x. extend ( s. iter ( ) . flat_map ( |& b| ascii:: escape_default ( b) ) . map ( char:: from) ) ;
1071
- x
1072
- } )
1060
+ match str:: from_utf8 ( s) {
1061
+ Ok ( s) => s. to_owned ( ) ,
1062
+ Err ( _) => format ! ( "Non-UTF-8 output: {}" , s. escape_ascii( ) ) ,
1063
+ }
1073
1064
}
1074
1065
1075
1066
fn add_sanitizer_libraries ( sess : & Session , crate_type : CrateType , linker : & mut dyn Linker ) {
0 commit comments