@@ -54,7 +54,6 @@ use fmt::{self, Debug, Display};
54
54
use marker:: Reflect ;
55
55
use mem:: transmute;
56
56
use num;
57
- use raw:: TraitObject ;
58
57
use str;
59
58
use string;
60
59
@@ -326,11 +325,7 @@ impl Error + 'static {
326
325
pub fn downcast_ref < T : Error + ' static > ( & self ) -> Option < & T > {
327
326
if self . is :: < T > ( ) {
328
327
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 ) )
334
329
}
335
330
} else {
336
331
None
@@ -344,11 +339,7 @@ impl Error + 'static {
344
339
pub fn downcast_mut < T : Error + ' static > ( & mut self ) -> Option < & mut T > {
345
340
if self . is :: < T > ( ) {
346
341
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 ) )
352
343
}
353
344
} else {
354
345
None
@@ -409,13 +400,8 @@ impl Error {
409
400
pub fn downcast < T : Error + ' static > ( self : Box < Self > ) -> Result < Box < T > , Box < Error > > {
410
401
if self . is :: < T > ( ) {
411
402
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 ) )
419
405
}
420
406
} else {
421
407
Err ( self )
0 commit comments