From 2b10df7f24828b09759277cc3a9c18c493c38ce0 Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Thu, 25 Aug 2016 20:56:47 -0400 Subject: Replace unnecessary uses of `TraitObject` with casts --- src/libstd/error.rs | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'src/libstd/error.rs') diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 44595361fb5..ab537f39bf9 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -54,7 +54,6 @@ use fmt::{self, Debug, Display}; use marker::Reflect; use mem::transmute; use num; -use raw::TraitObject; use str; use string; @@ -326,11 +325,7 @@ impl Error + 'static { pub fn downcast_ref(&self) -> Option<&T> { if self.is::() { unsafe { - // Get the raw representation of the trait object - let to: TraitObject = transmute(self); - - // Extract the data pointer - Some(&*(to.data as *const T)) + Some(&*(self as *const Error as *const T)) } } else { None @@ -344,11 +339,7 @@ impl Error + 'static { pub fn downcast_mut(&mut self) -> Option<&mut T> { if self.is::() { unsafe { - // Get the raw representation of the trait object - let to: TraitObject = transmute(self); - - // Extract the data pointer - Some(&mut *(to.data as *const T as *mut T)) + Some(&mut *(self as *mut Error as *mut T)) } } else { None @@ -409,13 +400,8 @@ impl Error { pub fn downcast(self: Box) -> Result, Box> { if self.is::() { unsafe { - // Get the raw representation of the trait object - let raw = Box::into_raw(self); - let to: TraitObject = - transmute::<*mut Error, TraitObject>(raw); - - // Extract the data pointer - Ok(Box::from_raw(to.data as *mut T)) + let raw: *mut Error = Box::into_raw(self); + Ok(Box::from_raw(raw as *mut T)) } } else { Err(self) -- cgit 1.4.1-3-g733a5