Skip to content

Commit 613e57b

Browse files
committed
Auto merge of #25246 - mzabaluev:io-invalid-data, r=alexcrichton
This takes the cases from `InvalidInput` where a data format error was encountered. This is different from the documented semantics of `InvalidInput`, which more likely indicate a programming error. Fixes rust-lang/rfcs#906
2 parents a49ae5b + 0ad019f commit 613e57b

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/libstd/io/error.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ pub enum ErrorKind {
9595
/// A parameter was incorrect.
9696
#[stable(feature = "rust1", since = "1.0.0")]
9797
InvalidInput,
98+
/// Data not valid for the operation were encountered.
99+
///
100+
/// Unlike `InvalidInput`, this typically means that the operation
101+
/// parameters were valid, however the error was caused by malformed
102+
/// input data.
103+
#[stable(feature = "io_invalid_data", since = "1.2.0")]
104+
InvalidData,
98105
/// The I/O operation's timeout expired, causing it to be canceled.
99106
#[stable(feature = "rust1", since = "1.0.0")]
100107
TimedOut,

src/libstd/io/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn append_to_string<F>(buf: &mut String, f: F) -> Result<usize>
8080
let ret = f(g.s);
8181
if str::from_utf8(&g.s[g.len..]).is_err() {
8282
ret.and_then(|_| {
83-
Err(Error::new(ErrorKind::InvalidInput,
83+
Err(Error::new(ErrorKind::InvalidData,
8484
"stream did not contain valid UTF-8"))
8585
})
8686
} else {

src/libstd/sys/windows/stdio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,5 @@ impl Output {
170170
}
171171

172172
fn invalid_encoding() -> io::Error {
173-
io::Error::new(io::ErrorKind::InvalidInput, "text was not valid unicode")
173+
io::Error::new(io::ErrorKind::InvalidData, "text was not valid unicode")
174174
}

0 commit comments

Comments
 (0)