diff options
| author | Pietro Albini <pietro@pietroalbini.org> | 2019-05-31 13:33:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-31 13:33:51 +0200 |
| commit | eebe62aaa1e31151269d19ec71248215a40f6417 (patch) | |
| tree | 3dc174831842db900bfffab2840cb8d98fdfb907 | |
| parent | 3ade426ede7bca4a74bc641a12f2e7fe2cc20c47 (diff) | |
| parent | d2d89b10de394b4a1d5e2491dfffd3d65d1741b3 (diff) | |
| download | rust-eebe62aaa1e31151269d19ec71248215a40f6417.tar.gz rust-eebe62aaa1e31151269d19ec71248215a40f6417.zip | |
Rollup merge of #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" }
```
| -rw-r--r-- | src/libstd/error.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/libstd/error.rs b/src/libstd/error.rs index c8978a94fcd..5cc7dcdae1f 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -314,7 +314,6 @@ impl From<String> for Box<dyn Error + Send + Sync> { /// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error)) /// ``` fn from(err: String) -> Box<dyn Error + Send + Sync> { - #[derive(Debug)] struct StringError(String); impl Error for StringError { @@ -327,6 +326,13 @@ impl From<String> for Box<dyn Error + Send + Sync> { } } + // 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)) } } |
