From 972b008a6e15defd9d7d8dfb9073091b341b716a Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 1 Aug 2018 09:42:12 -0700 Subject: [PATCH] remove unsafe error transmute, upgrade failure to 0.1.2 #434 --- Cargo.toml | 2 +- src/error.rs | 17 +++-------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 695b2e31f..31440eb37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,7 +83,7 @@ cookie = { version="0.11", features=["percent-encode"] } brotli2 = { version="^0.3.2", optional = true } flate2 = { version="^1.0.2", optional = true, default-features = false } -failure = "=0.1.1" +failure = "^0.1.2" # io mio = "^0.6.13" diff --git a/src/error.rs b/src/error.rs index 461b23e20..76c8e79ec 100644 --- a/src/error.rs +++ b/src/error.rs @@ -52,7 +52,8 @@ pub struct Error { impl Error { /// Deprecated way to reference the underlying response error. #[deprecated( - since = "0.6.0", note = "please use `Error::as_response_error()` instead" + since = "0.6.0", + note = "please use `Error::as_response_error()` instead" )] pub fn cause(&self) -> &ResponseError { self.cause.as_ref() @@ -97,21 +98,9 @@ impl Error { // // So we first downcast into that compat, to then further downcast through // the failure's Error downcasting system into the original failure. - // - // This currently requires a transmute. This could be avoided if failure - // provides a deref: https://github.com/rust-lang-nursery/failure/pull/213 let compat: Option<&failure::Compat> = Fail::downcast_ref(self.cause.as_fail()); - if let Some(compat) = compat { - pub struct CompatWrappedError { - error: failure::Error, - } - let compat: &CompatWrappedError = - unsafe { &*(compat as *const _ as *const CompatWrappedError) }; - compat.error.downcast_ref() - } else { - None - } + compat.and_then(|e| e.get_ref().downcast_ref()) } }