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" }
```
This commit is contained in:
Pietro Albini 2019-05-31 13:33:51 +02:00 committed by GitHub
commit eebe62aaa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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))
}
}