@@ -407,56 +407,65 @@ impl Error for UIoError {}
407407
408408impl Display for UIoError {
409409 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result < ( ) , std:: fmt:: Error > {
410- use std:: io:: ErrorKind :: * ;
411-
412- let message;
413- let message = if self . inner . raw_os_error ( ) . is_some ( ) {
414- // These are errors that come directly from the OS.
415- // We want to normalize their messages across systems,
416- // and we want to strip the "(os error X)" suffix.
417- match self . inner . kind ( ) {
418- NotFound => "No such file or directory" ,
419- PermissionDenied => "Permission denied" ,
420- ConnectionRefused => "Connection refused" ,
421- ConnectionReset => "Connection reset" ,
422- ConnectionAborted => "Connection aborted" ,
423- NotConnected => "Not connected" ,
424- AddrInUse => "Address in use" ,
425- AddrNotAvailable => "Address not available" ,
426- BrokenPipe => "Broken pipe" ,
427- AlreadyExists => "Already exists" ,
428- WouldBlock => "Would block" ,
429- InvalidInput => "Invalid input" ,
430- InvalidData => "Invalid data" ,
431- TimedOut => "Timed out" ,
432- WriteZero => "Write zero" ,
433- Interrupted => "Interrupted" ,
434- UnexpectedEof => "Unexpected end of file" ,
435- _ => {
436- // TODO: When the new error variants
437- // (https://github.com/rust-lang/rust/issues/86442)
438- // are stabilized, we should add them to the match statement.
439- message = strip_errno ( & self . inner ) ;
440- & message
441- }
410+ cold_io_error ( f, & self . context , & self . inner )
411+ }
412+ }
413+
414+ #[ cold] //for codegen-units=1
415+ #[ inline( never) ]
416+ fn cold_io_error (
417+ f : & mut Formatter < ' _ > ,
418+ ctx : & Option < String > ,
419+ inner : & std:: io:: Error ,
420+ ) -> Result < ( ) , std:: fmt:: Error > {
421+ use std:: io:: ErrorKind :: * ;
422+
423+ let message_hold;
424+ let message = if inner. raw_os_error ( ) . is_some ( ) {
425+ // These are errors that come directly from the OS.
426+ // We want to normalize their messages across systems,
427+ // and we want to strip the "(os error X)" suffix.
428+ match inner. kind ( ) {
429+ NotFound => "No such file or directory" ,
430+ PermissionDenied => "Permission denied" ,
431+ ConnectionRefused => "Connection refused" ,
432+ ConnectionReset => "Connection reset" ,
433+ ConnectionAborted => "Connection aborted" ,
434+ NotConnected => "Not connected" ,
435+ AddrInUse => "Address in use" ,
436+ AddrNotAvailable => "Address not available" ,
437+ BrokenPipe => "Broken pipe" ,
438+ AlreadyExists => "Already exists" ,
439+ WouldBlock => "Would block" ,
440+ InvalidInput => "Invalid input" ,
441+ InvalidData => "Invalid data" ,
442+ TimedOut => "Timed out" ,
443+ WriteZero => "Write zero" ,
444+ Interrupted => "Interrupted" ,
445+ UnexpectedEof => "Unexpected end of file" ,
446+ _ => {
447+ // TODO: When the new error variants
448+ // (https://github.com/rust-lang/rust/issues/86442)
449+ // are stabilized, we should add them to the match statement.
450+ message_hold = strip_errno ( inner) ;
451+ & message_hold
442452 }
443- } else {
444- // These messages don't need as much normalization, and the above
445- // messages wouldn't always be a good substitute.
446- // For example, ErrorKind::NotFound doesn't necessarily mean it was
447- // a file that was not found.
448- // There are also errors with entirely custom messages.
449- message = self . inner . to_string ( ) ;
450- & message
451- } ;
452- if let Some ( ctx) = & self . context {
453- write ! ( f, "{ctx}: {message}" )
454- } else {
455- write ! ( f, "{message}" )
456453 }
454+ } else {
455+ // These messages don't need as much normalization, and the above
456+ // messages wouldn't always be a good substitute.
457+ // For example, ErrorKind::NotFound doesn't necessarily mean it was
458+ // a file that was not found.
459+ // There are also errors with entirely custom messages.
460+ message_hold = inner. to_string ( ) ;
461+ & message_hold
462+ } ;
463+ if let Some ( c) = ctx {
464+ write ! ( f, "{c}: {message}" )
465+ } else {
466+ write ! ( f, "{message}" )
457467 }
458468}
459-
460469/// Strip the trailing " (os error XX)" from io error strings.
461470pub fn strip_errno ( err : & std:: io:: Error ) -> String {
462471 let mut msg = err. to_string ( ) ;
0 commit comments