@@ -54,7 +54,6 @@ use fmt::{self, Debug, Display};
5454use marker:: Reflect ;
5555use mem:: transmute;
5656use num;
57- use raw:: TraitObject ;
5857use str;
5958use string;
6059
@@ -326,11 +325,7 @@ impl Error + 'static {
326325 pub fn downcast_ref < T : Error + ' static > ( & self ) -> Option < & T > {
327326 if self . is :: < T > ( ) {
328327 unsafe {
329- // Get the raw representation of the trait object
330- let to: TraitObject = transmute ( self ) ;
331-
332- // Extract the data pointer
333- Some ( & * ( to. data as * const T ) )
328+ Some ( & * ( self as * const Error as * const T ) )
334329 }
335330 } else {
336331 None
@@ -344,11 +339,7 @@ impl Error + 'static {
344339 pub fn downcast_mut < T : Error + ' static > ( & mut self ) -> Option < & mut T > {
345340 if self . is :: < T > ( ) {
346341 unsafe {
347- // Get the raw representation of the trait object
348- let to: TraitObject = transmute ( self ) ;
349-
350- // Extract the data pointer
351- Some ( & mut * ( to. data as * const T as * mut T ) )
342+ Some ( & mut * ( self as * mut Error as * mut T ) )
352343 }
353344 } else {
354345 None
@@ -409,13 +400,8 @@ impl Error {
409400 pub fn downcast < T : Error + ' static > ( self : Box < Self > ) -> Result < Box < T > , Box < Error > > {
410401 if self . is :: < T > ( ) {
411402 unsafe {
412- // Get the raw representation of the trait object
413- let raw = Box :: into_raw ( self ) ;
414- let to: TraitObject =
415- transmute :: < * mut Error , TraitObject > ( raw) ;
416-
417- // Extract the data pointer
418- Ok ( Box :: from_raw ( to. data as * mut T ) )
403+ let raw: * mut Error = Box :: into_raw ( self ) ;
404+ Ok ( Box :: from_raw ( raw as * mut T ) )
419405 }
420406 } else {
421407 Err ( self )
0 commit comments