Skip to content

Commit

Permalink
auto merge of #13799 : m-r-r/rust/patch-std-io-standard_error, r=alex…
Browse files Browse the repository at this point in the history
…crichton

Hello,

With the latest version of Rust, calling to the function [`std::io::standard_error()`](http://static.rust-lang.org/doc/master/std/io/fn.standard_error.html) succeeds only if the value of the argument is `EndOfFile`, `IoUnavailable` or `InvalidInput`. If the function is called with another value as argument, it fails without message.

Here is a piece of code that reproduces the problem:

```rust
use std::io::{standard_error,EndOfFile,FileNotFound,PermissionDenied};

fn main() {
     println!("Error 1: {}", standard_error(EndOfFile)); // does not fail
     println!("Error 2: {}", standard_error(FileNotFound)); // fails
     println!("Error 3: {}", standard_error(PermissionDenied)); //fails
}
```
This was because the `IoErrorKind` passed as argument wasn't matched against all the possible values.

I added the missing branches in the `match` statement inside the function, and i removed the call to the `fail!()` macro. I rebuilt the crate with the latest `rustc` version and it seems to works.
  • Loading branch information
bors committed Apr 27, 2014
2 parents 479b8a8 + a7b8a13 commit 8b24964
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,21 @@ pub fn standard_error(kind: IoErrorKind) -> IoError {
EndOfFile => "end of file",
IoUnavailable => "I/O is unavailable",
InvalidInput => "invalid input",
_ => fail!()
OtherIoError => "unknown I/O error",
FileNotFound => "file not found",
PermissionDenied => "permission denied",
ConnectionFailed => "connection failed",
Closed => "stream is closed",
ConnectionRefused => "connection refused",
ConnectionReset => "connection reset",
ConnectionAborted => "connection aborted",
NotConnected => "not connected",
BrokenPipe => "broken pipe",
PathAlreadyExists => "file exists",
PathDoesntExist => "no such file",
MismatchedFileTypeForOperation => "mismatched file type",
ResourceUnavailable => "resource unavailable",
TimedOut => "operation timed out"
};
IoError {
kind: kind,
Expand Down

0 comments on commit 8b24964

Please sign in to comment.