@@ -138,7 +138,7 @@ pub trait Error: Debug + Display {
138
138
/// }
139
139
/// ```
140
140
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
141
- fn cause ( & self ) -> Option < & Error > { None }
141
+ fn cause ( & self ) -> Option < & dyn Error > { None }
142
142
143
143
/// Get the `TypeId` of `self`
144
144
#[ doc( hidden) ]
@@ -151,22 +151,22 @@ pub trait Error: Debug + Display {
151
151
}
152
152
153
153
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
154
- impl < ' a , E : Error + ' a > From < E > for Box < Error + ' a > {
155
- fn from ( err : E ) -> Box < Error + ' a > {
154
+ impl < ' a , E : Error + ' a > From < E > for Box < dyn Error + ' a > {
155
+ fn from ( err : E ) -> Box < dyn Error + ' a > {
156
156
Box :: new ( err)
157
157
}
158
158
}
159
159
160
160
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
161
- impl < ' a , E : Error + Send + Sync + ' a > From < E > for Box < Error + Send + Sync + ' a > {
162
- fn from ( err : E ) -> Box < Error + Send + Sync + ' a > {
161
+ impl < ' a , E : Error + Send + Sync + ' a > From < E > for Box < dyn Error + Send + Sync + ' a > {
162
+ fn from ( err : E ) -> Box < dyn Error + Send + Sync + ' a > {
163
163
Box :: new ( err)
164
164
}
165
165
}
166
166
167
167
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
168
- impl From < String > for Box < Error + Send + Sync > {
169
- fn from ( err : String ) -> Box < Error + Send + Sync > {
168
+ impl From < String > for Box < dyn Error + Send + Sync > {
169
+ fn from ( err : String ) -> Box < dyn Error + Send + Sync > {
170
170
#[ derive( Debug ) ]
171
171
struct StringError ( String ) ;
172
172
@@ -185,38 +185,38 @@ impl From<String> for Box<Error + Send + Sync> {
185
185
}
186
186
187
187
#[ stable( feature = "string_box_error" , since = "1.6.0" ) ]
188
- impl From < String > for Box < Error > {
189
- fn from ( str_err : String ) -> Box < Error > {
190
- let err1: Box < Error + Send + Sync > = From :: from ( str_err) ;
191
- let err2: Box < Error > = err1;
188
+ impl From < String > for Box < dyn Error > {
189
+ fn from ( str_err : String ) -> Box < dyn Error > {
190
+ let err1: Box < dyn Error + Send + Sync > = From :: from ( str_err) ;
191
+ let err2: Box < dyn Error > = err1;
192
192
err2
193
193
}
194
194
}
195
195
196
196
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
197
- impl < ' a , ' b > From < & ' b str > for Box < Error + Send + Sync + ' a > {
198
- fn from ( err : & ' b str ) -> Box < Error + Send + Sync + ' a > {
197
+ impl < ' a , ' b > From < & ' b str > for Box < dyn Error + Send + Sync + ' a > {
198
+ fn from ( err : & ' b str ) -> Box < dyn Error + Send + Sync + ' a > {
199
199
From :: from ( String :: from ( err) )
200
200
}
201
201
}
202
202
203
203
#[ stable( feature = "string_box_error" , since = "1.6.0" ) ]
204
- impl < ' a > From < & ' a str > for Box < Error > {
205
- fn from ( err : & ' a str ) -> Box < Error > {
204
+ impl < ' a > From < & ' a str > for Box < dyn Error > {
205
+ fn from ( err : & ' a str ) -> Box < dyn Error > {
206
206
From :: from ( String :: from ( err) )
207
207
}
208
208
}
209
209
210
210
#[ stable( feature = "cow_box_error" , since = "1.22.0" ) ]
211
- impl < ' a , ' b > From < Cow < ' b , str > > for Box < Error + Send + Sync + ' a > {
212
- fn from ( err : Cow < ' b , str > ) -> Box < Error + Send + Sync + ' a > {
211
+ impl < ' a , ' b > From < Cow < ' b , str > > for Box < dyn Error + Send + Sync + ' a > {
212
+ fn from ( err : Cow < ' b , str > ) -> Box < dyn Error + Send + Sync + ' a > {
213
213
From :: from ( String :: from ( err) )
214
214
}
215
215
}
216
216
217
217
#[ stable( feature = "cow_box_error" , since = "1.22.0" ) ]
218
- impl < ' a > From < Cow < ' a , str > > for Box < Error > {
219
- fn from ( err : Cow < ' a , str > ) -> Box < Error > {
218
+ impl < ' a > From < Cow < ' a , str > > for Box < dyn Error > {
219
+ fn from ( err : Cow < ' a , str > ) -> Box < dyn Error > {
220
220
From :: from ( String :: from ( err) )
221
221
}
222
222
}
@@ -327,7 +327,7 @@ impl<T: Error> Error for Box<T> {
327
327
Error :: description ( & * * self )
328
328
}
329
329
330
- fn cause ( & self ) -> Option < & Error > {
330
+ fn cause ( & self ) -> Option < & dyn Error > {
331
331
Error :: cause ( & * * self )
332
332
}
333
333
}
@@ -368,7 +368,7 @@ impl Error for char::ParseCharError {
368
368
}
369
369
370
370
// copied from any.rs
371
- impl Error + ' static {
371
+ impl dyn Error + ' static {
372
372
/// Returns true if the boxed type is the same as `T`
373
373
#[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
374
374
#[ inline]
@@ -390,7 +390,7 @@ impl Error + 'static {
390
390
pub fn downcast_ref < T : Error + ' static > ( & self ) -> Option < & T > {
391
391
if self . is :: < T > ( ) {
392
392
unsafe {
393
- Some ( & * ( self as * const Error as * const T ) )
393
+ Some ( & * ( self as * const dyn Error as * const T ) )
394
394
}
395
395
} else {
396
396
None
@@ -404,68 +404,68 @@ impl Error + 'static {
404
404
pub fn downcast_mut < T : Error + ' static > ( & mut self ) -> Option < & mut T > {
405
405
if self . is :: < T > ( ) {
406
406
unsafe {
407
- Some ( & mut * ( self as * mut Error as * mut T ) )
407
+ Some ( & mut * ( self as * mut dyn Error as * mut T ) )
408
408
}
409
409
} else {
410
410
None
411
411
}
412
412
}
413
413
}
414
414
415
- impl Error + ' static + Send {
415
+ impl dyn Error + ' static + Send {
416
416
/// Forwards to the method defined on the type `Any`.
417
417
#[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
418
418
#[ inline]
419
419
pub fn is < T : Error + ' static > ( & self ) -> bool {
420
- <Error + ' static >:: is :: < T > ( self )
420
+ <dyn Error + ' static >:: is :: < T > ( self )
421
421
}
422
422
423
423
/// Forwards to the method defined on the type `Any`.
424
424
#[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
425
425
#[ inline]
426
426
pub fn downcast_ref < T : Error + ' static > ( & self ) -> Option < & T > {
427
- <Error + ' static >:: downcast_ref :: < T > ( self )
427
+ <dyn Error + ' static >:: downcast_ref :: < T > ( self )
428
428
}
429
429
430
430
/// Forwards to the method defined on the type `Any`.
431
431
#[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
432
432
#[ inline]
433
433
pub fn downcast_mut < T : Error + ' static > ( & mut self ) -> Option < & mut T > {
434
- <Error + ' static >:: downcast_mut :: < T > ( self )
434
+ <dyn Error + ' static >:: downcast_mut :: < T > ( self )
435
435
}
436
436
}
437
437
438
- impl Error + ' static + Send + Sync {
438
+ impl dyn Error + ' static + Send + Sync {
439
439
/// Forwards to the method defined on the type `Any`.
440
440
#[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
441
441
#[ inline]
442
442
pub fn is < T : Error + ' static > ( & self ) -> bool {
443
- <Error + ' static >:: is :: < T > ( self )
443
+ <dyn Error + ' static >:: is :: < T > ( self )
444
444
}
445
445
446
446
/// Forwards to the method defined on the type `Any`.
447
447
#[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
448
448
#[ inline]
449
449
pub fn downcast_ref < T : Error + ' static > ( & self ) -> Option < & T > {
450
- <Error + ' static >:: downcast_ref :: < T > ( self )
450
+ <dyn Error + ' static >:: downcast_ref :: < T > ( self )
451
451
}
452
452
453
453
/// Forwards to the method defined on the type `Any`.
454
454
#[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
455
455
#[ inline]
456
456
pub fn downcast_mut < T : Error + ' static > ( & mut self ) -> Option < & mut T > {
457
- <Error + ' static >:: downcast_mut :: < T > ( self )
457
+ <dyn Error + ' static >:: downcast_mut :: < T > ( self )
458
458
}
459
459
}
460
460
461
- impl Error {
461
+ impl dyn Error {
462
462
#[ inline]
463
463
#[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
464
464
/// Attempt to downcast the box to a concrete type.
465
- pub fn downcast < T : Error + ' static > ( self : Box < Self > ) -> Result < Box < T > , Box < Error > > {
465
+ pub fn downcast < T : Error + ' static > ( self : Box < Self > ) -> Result < Box < T > , Box < dyn Error > > {
466
466
if self . is :: < T > ( ) {
467
467
unsafe {
468
- let raw: * mut Error = Box :: into_raw ( self ) ;
468
+ let raw: * mut dyn Error = Box :: into_raw ( self ) ;
469
469
Ok ( Box :: from_raw ( raw as * mut T ) )
470
470
}
471
471
} else {
@@ -474,30 +474,30 @@ impl Error {
474
474
}
475
475
}
476
476
477
- impl Error + Send {
477
+ impl dyn Error + Send {
478
478
#[ inline]
479
479
#[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
480
480
/// Attempt to downcast the box to a concrete type.
481
481
pub fn downcast < T : Error + ' static > ( self : Box < Self > )
482
- -> Result < Box < T > , Box < Error + Send > > {
483
- let err: Box < Error > = self ;
484
- <Error >:: downcast ( err) . map_err ( |s| unsafe {
482
+ -> Result < Box < T > , Box < dyn Error + Send > > {
483
+ let err: Box < dyn Error > = self ;
484
+ <dyn Error >:: downcast ( err) . map_err ( |s| unsafe {
485
485
// reapply the Send marker
486
- transmute :: < Box < Error > , Box < Error + Send > > ( s)
486
+ transmute :: < Box < dyn Error > , Box < dyn Error + Send > > ( s)
487
487
} )
488
488
}
489
489
}
490
490
491
- impl Error + Send + Sync {
491
+ impl dyn Error + Send + Sync {
492
492
#[ inline]
493
493
#[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
494
494
/// Attempt to downcast the box to a concrete type.
495
495
pub fn downcast < T : Error + ' static > ( self : Box < Self > )
496
496
-> Result < Box < T > , Box < Self > > {
497
- let err: Box < Error > = self ;
498
- <Error >:: downcast ( err) . map_err ( |s| unsafe {
497
+ let err: Box < dyn Error > = self ;
498
+ <dyn Error >:: downcast ( err) . map_err ( |s| unsafe {
499
499
// reapply the Send+Sync marker
500
- transmute :: < Box < Error > , Box < Error + Send + Sync > > ( s)
500
+ transmute :: < Box < dyn Error > , Box < dyn Error + Send + Sync > > ( s)
501
501
} )
502
502
}
503
503
}
@@ -533,13 +533,13 @@ mod tests {
533
533
#[ test]
534
534
fn downcasting ( ) {
535
535
let mut a = A ;
536
- let a = & mut a as & mut ( Error + ' static ) ;
536
+ let a = & mut a as & mut ( dyn Error + ' static ) ;
537
537
assert_eq ! ( a. downcast_ref:: <A >( ) , Some ( & A ) ) ;
538
538
assert_eq ! ( a. downcast_ref:: <B >( ) , None ) ;
539
539
assert_eq ! ( a. downcast_mut:: <A >( ) , Some ( & mut A ) ) ;
540
540
assert_eq ! ( a. downcast_mut:: <B >( ) , None ) ;
541
541
542
- let a: Box < Error > = Box :: new ( A ) ;
542
+ let a: Box < dyn Error > = Box :: new ( A ) ;
543
543
match a. downcast :: < B > ( ) {
544
544
Ok ( ..) => panic ! ( "expected error" ) ,
545
545
Err ( e) => assert_eq ! ( * e. downcast:: <A >( ) . unwrap( ) , A ) ,
0 commit comments