@@ -44,7 +44,7 @@ use std::io::{BufWriter, Write};
4444use std:: ops:: Deref ;
4545use std:: path:: { Path , PathBuf } ;
4646use 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} ;
4848
4949pub fn ensure_removed ( diag_handler : & Handler , path : & Path ) {
5050 if let Err ( e) = fs:: remove_file ( path) {
@@ -552,14 +552,6 @@ fn link_staticlib<'a>(
552552 Ok ( ( ) )
553553}
554554
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-
563555/// Use `thorin` (rust implementation of a dwarf packaging utility) to link DWARF objects into a
564556/// DWARF package.
565557fn link_dwarf_object < ' a > (
@@ -866,7 +858,7 @@ fn link_natively<'a>(
866858 if !prog. status . success ( ) {
867859 let mut output = prog. stderr . clone ( ) ;
868860 output. extend_from_slice ( & prog. stdout ) ;
869- let escaped_output = escape_stdout_stderr_string ( & output) ;
861+ let escaped_output = escape_string ( & output) ;
870862 let mut err = sess. struct_err ( & format ! (
871863 "linking with `{}` failed: {}" ,
872864 linker_path. display( ) ,
@@ -934,8 +926,8 @@ fn link_natively<'a>(
934926
935927 sess. abort_if_errors ( ) ;
936928 }
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) ) ;
939931 }
940932 Err ( e) => {
941933 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
10651057}
10661058
10671059fn 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+ }
10731064}
10741065
10751066fn add_sanitizer_libraries ( sess : & Session , crate_type : CrateType , linker : & mut dyn Linker ) {
0 commit comments