Skip to content

Commit eebe62a

Browse files
authored
Rollup merge of rust-lang#60897 - seanmonstar:patch-4, r=sfackler
error: remove StringError from Debug output Seeing `StringError("something something")` in debug output can cause someone to think there was an error dealing with `String`s, not that the error type is just a string. So, remove that noise. For example: ``` io error: Custom { kind: InvalidData, error: StringError("corrupt data") } ``` With this change: ``` io error: Custom { kind: InvalidData, error: "corrupt data" } ```
2 parents 3ade426 + d2d89b1 commit eebe62a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/libstd/error.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ impl From<String> for Box<dyn Error + Send + Sync> {
314314
/// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
315315
/// ```
316316
fn from(err: String) -> Box<dyn Error + Send + Sync> {
317-
#[derive(Debug)]
318317
struct StringError(String);
319318

320319
impl Error for StringError {
@@ -327,6 +326,13 @@ impl From<String> for Box<dyn Error + Send + Sync> {
327326
}
328327
}
329328

329+
// Purposefully skip printing "StringError(..)"
330+
impl Debug for StringError {
331+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
332+
Debug::fmt(&self.0, f)
333+
}
334+
}
335+
330336
Box::new(StringError(err))
331337
}
332338
}

0 commit comments

Comments
 (0)