about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-08-27 03:07:48 -0700
committerGitHub <noreply@github.com>2016-08-27 03:07:48 -0700
commit099b9fdb1a170b57ffd7174b3c3042cc86b7fe91 (patch)
treeaa3b27019254450634a4fea8583e7cc70d7b7190 /src/libstd
parent6b74503aa4f2fb4035d9adef9391e9b9658c57ad (diff)
parent668d63132e23999f5a74fe65c8c0590a4d9ca215 (diff)
downloadrust-099b9fdb1a170b57ffd7174b3c3042cc86b7fe91.tar.gz
rust-099b9fdb1a170b57ffd7174b3c3042cc86b7fe91.zip
Auto merge of #36030 - Manishearth:rollup, r=Manishearth
Rollup of 7 pull requests

- Successful merges: #35124, #35877, #35953, #36002, #36004, #36005, #36014
- Failed merges:
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/error.rs22
1 files changed, 4 insertions, 18 deletions
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<T: Error + 'static>(&self) -> Option<&T> {
         if self.is::<T>() {
             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<T: Error + 'static>(&mut self) -> Option<&mut T> {
         if self.is::<T>() {
             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<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<Error>> {
         if self.is::<T>() {
             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)