Skip to content

Commit d2d89b1

Browse files
committed
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.
1 parent 7d5aa43 commit d2d89b1

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
@@ -300,7 +300,6 @@ impl From<String> for Box<dyn Error + Send + Sync> {
300300
/// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
301301
/// ```
302302
fn from(err: String) -> Box<dyn Error + Send + Sync> {
303-
#[derive(Debug)]
304303
struct StringError(String);
305304

306305
impl Error for StringError {
@@ -313,6 +312,13 @@ impl From<String> for Box<dyn Error + Send + Sync> {
313312
}
314313
}
315314

315+
// Purposefully skip printing "StringError(..)"
316+
impl Debug for StringError {
317+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
318+
Debug::fmt(&self.0, f)
319+
}
320+
}
321+
316322
Box::new(StringError(err))
317323
}
318324
}

0 commit comments

Comments
 (0)