Skip to content

Commit 9a6b611

Browse files
committed
Custom Debug impl for io::Error
Fixes #26408 Signed-off-by: Peter Atashian <[email protected]>
1 parent ff8fee1 commit 9a6b611

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/libstd/io/error.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ pub struct Error {
3737
repr: Repr,
3838
}
3939

40-
#[derive(Debug)]
4140
enum Repr {
4241
Os(i32),
4342
Custom(Box<Custom>),
@@ -240,6 +239,17 @@ impl Error {
240239
}
241240
}
242241

242+
impl fmt::Debug for Repr {
243+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
244+
match self {
245+
&Repr::Os(ref code) =>
246+
fmt.debug_struct("Os").field("code", code)
247+
.field("message", &sys::os::error_string(*code)).finish(),
248+
&Repr::Custom(ref c) => fmt.debug_tuple("Custom").field(c).finish(),
249+
}
250+
}
251+
}
252+
243253
#[stable(feature = "rust1", since = "1.0.0")]
244254
impl fmt::Display for Error {
245255
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {

0 commit comments

Comments
 (0)