about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2016-08-27 09:31:15 +0530
committerGitHub <noreply@github.com>2016-08-27 09:31:15 +0530
commit30835ec4e4f415e917b3e89edc8033789d1b009f (patch)
treef708d72391df676805df764884027173b7c9942a
parent933d481bdd1ad64804173e09a257dc46535d333e (diff)
parent2b10df7f24828b09759277cc3a9c18c493c38ce0 (diff)
downloadrust-30835ec4e4f415e917b3e89edc8033789d1b009f.tar.gz
rust-30835ec4e4f415e917b3e89edc8033789d1b009f.zip
Rollup merge of #36005 - apasel422:traitobj, r=alexcrichton
Replace unnecessary uses of `TraitObject` with casts

r? @alexcrichton
-rw-r--r--src/liballoc/boxed.rs9
-rw-r--r--src/liballoc/lib.rs2
-rw-r--r--src/libcore/any.rs14
-rw-r--r--src/libstd/error.rs22
4 files changed, 9 insertions, 38 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
index dae12f6e8bd..c8a78f84f18 100644
--- a/src/liballoc/boxed.rs
+++ b/src/liballoc/boxed.rs
@@ -67,7 +67,6 @@ use core::mem;
 use core::ops::{CoerceUnsized, Deref, DerefMut};
 use core::ops::{BoxPlace, Boxed, InPlace, Place, Placer};
 use core::ptr::{self, Unique};
-use core::raw::TraitObject;
 use core::convert::From;
 
 /// A value that represents the heap. This is the default place that the `box`
@@ -428,12 +427,8 @@ impl Box<Any> {
     pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
         if self.is::<T>() {
             unsafe {
-                // Get the raw representation of the trait object
-                let raw = Box::into_raw(self);
-                let to: TraitObject = mem::transmute::<*mut Any, TraitObject>(raw);
-
-                // Extract the data pointer
-                Ok(Box::from_raw(to.data as *mut T))
+                let raw: *mut Any = Box::into_raw(self);
+                Ok(Box::from_raw(raw as *mut T))
             }
         } else {
             Err(self)
diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs
index d9fd2d92710..c6453da3f46 100644
--- a/src/liballoc/lib.rs
+++ b/src/liballoc/lib.rs
@@ -91,7 +91,7 @@
 #![cfg_attr(stage0, feature(unsafe_no_drop_flag))]
 #![feature(unsize)]
 
-#![cfg_attr(not(test), feature(fused, raw, fn_traits, placement_new_protocol))]
+#![cfg_attr(not(test), feature(fused, fn_traits, placement_new_protocol))]
 #![cfg_attr(test, feature(test, box_heap))]
 
 // Allow testing this library
diff --git a/src/libcore/any.rs b/src/libcore/any.rs
index 4f486ad7cb8..a3018a46eea 100644
--- a/src/libcore/any.rs
+++ b/src/libcore/any.rs
@@ -72,8 +72,6 @@
 #![stable(feature = "rust1", since = "1.0.0")]
 
 use fmt;
-use mem::transmute;
-use raw::TraitObject;
 use intrinsics;
 use marker::Reflect;
 
@@ -199,11 +197,7 @@ impl Any {
     pub fn downcast_ref<T: Any>(&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 Any as *const T))
             }
         } else {
             None
@@ -240,11 +234,7 @@ impl Any {
     pub fn downcast_mut<T: Any>(&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 Any as *mut T))
             }
         } else {
             None
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)