From d2d89b10de394b4a1d5e2491dfffd3d65d1741b3 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Thu, 16 May 2019 17:09:04 -0700 Subject: [PATCH] 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. --- src/libstd/error.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 7cb830e751a..9424e059a14 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -300,7 +300,6 @@ impl From for Box { /// mem::size_of::>() == mem::size_of_val(&a_boxed_error)) /// ``` fn from(err: String) -> Box { - #[derive(Debug)] struct StringError(String); impl Error for StringError { @@ -313,6 +312,13 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { } } + // Purposefully skip printing "StringError(..)" + impl Debug for StringError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + Debug::fmt(&self.0, f) + } + } + Box::new(StringError(err)) } } -- 2.44.0