@@ -138,7 +138,7 @@ pub trait Error: Debug + Display {
138138 /// }
139139 /// ```
140140 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
141- fn cause ( & self ) -> Option < & Error > { None }
141+ fn cause ( & self ) -> Option < & dyn Error > { None }
142142
143143 /// Get the `TypeId` of `self`
144144 #[ doc( hidden) ]
@@ -151,22 +151,22 @@ pub trait Error: Debug + Display {
151151}
152152
153153#[ 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 > {
156156 Box :: new ( err)
157157 }
158158}
159159
160160#[ 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 > {
163163 Box :: new ( err)
164164 }
165165}
166166
167167#[ 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 > {
170170 #[ derive( Debug ) ]
171171 struct StringError ( String ) ;
172172
@@ -185,38 +185,38 @@ impl From<String> for Box<Error + Send + Sync> {
185185}
186186
187187#[ 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;
192192 err2
193193 }
194194}
195195
196196#[ 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 > {
199199 From :: from ( String :: from ( err) )
200200 }
201201}
202202
203203#[ 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 > {
206206 From :: from ( String :: from ( err) )
207207 }
208208}
209209
210210#[ 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 > {
213213 From :: from ( String :: from ( err) )
214214 }
215215}
216216
217217#[ 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 > {
220220 From :: from ( String :: from ( err) )
221221 }
222222}
@@ -327,7 +327,7 @@ impl<T: Error> Error for Box<T> {
327327 Error :: description ( & * * self )
328328 }
329329
330- fn cause ( & self ) -> Option < & Error > {
330+ fn cause ( & self ) -> Option < & dyn Error > {
331331 Error :: cause ( & * * self )
332332 }
333333}
@@ -368,7 +368,7 @@ impl Error for char::ParseCharError {
368368}
369369
370370// copied from any.rs
371- impl Error + ' static {
371+ impl dyn Error + ' static {
372372 /// Returns true if the boxed type is the same as `T`
373373 #[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
374374 #[ inline]
@@ -390,7 +390,7 @@ impl Error + 'static {
390390 pub fn downcast_ref < T : Error + ' static > ( & self ) -> Option < & T > {
391391 if self . is :: < T > ( ) {
392392 unsafe {
393- Some ( & * ( self as * const Error as * const T ) )
393+ Some ( & * ( self as * const dyn Error as * const T ) )
394394 }
395395 } else {
396396 None
@@ -404,68 +404,68 @@ impl Error + 'static {
404404 pub fn downcast_mut < T : Error + ' static > ( & mut self ) -> Option < & mut T > {
405405 if self . is :: < T > ( ) {
406406 unsafe {
407- Some ( & mut * ( self as * mut Error as * mut T ) )
407+ Some ( & mut * ( self as * mut dyn Error as * mut T ) )
408408 }
409409 } else {
410410 None
411411 }
412412 }
413413}
414414
415- impl Error + ' static + Send {
415+ impl dyn Error + ' static + Send {
416416 /// Forwards to the method defined on the type `Any`.
417417 #[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
418418 #[ inline]
419419 pub fn is < T : Error + ' static > ( & self ) -> bool {
420- <Error + ' static >:: is :: < T > ( self )
420+ <dyn Error + ' static >:: is :: < T > ( self )
421421 }
422422
423423 /// Forwards to the method defined on the type `Any`.
424424 #[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
425425 #[ inline]
426426 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 )
428428 }
429429
430430 /// Forwards to the method defined on the type `Any`.
431431 #[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
432432 #[ inline]
433433 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 )
435435 }
436436}
437437
438- impl Error + ' static + Send + Sync {
438+ impl dyn Error + ' static + Send + Sync {
439439 /// Forwards to the method defined on the type `Any`.
440440 #[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
441441 #[ inline]
442442 pub fn is < T : Error + ' static > ( & self ) -> bool {
443- <Error + ' static >:: is :: < T > ( self )
443+ <dyn Error + ' static >:: is :: < T > ( self )
444444 }
445445
446446 /// Forwards to the method defined on the type `Any`.
447447 #[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
448448 #[ inline]
449449 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 )
451451 }
452452
453453 /// Forwards to the method defined on the type `Any`.
454454 #[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
455455 #[ inline]
456456 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 )
458458 }
459459}
460460
461- impl Error {
461+ impl dyn Error {
462462 #[ inline]
463463 #[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
464464 /// 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 > > {
466466 if self . is :: < T > ( ) {
467467 unsafe {
468- let raw: * mut Error = Box :: into_raw ( self ) ;
468+ let raw: * mut dyn Error = Box :: into_raw ( self ) ;
469469 Ok ( Box :: from_raw ( raw as * mut T ) )
470470 }
471471 } else {
@@ -474,30 +474,30 @@ impl Error {
474474 }
475475}
476476
477- impl Error + Send {
477+ impl dyn Error + Send {
478478 #[ inline]
479479 #[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
480480 /// Attempt to downcast the box to a concrete type.
481481 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 {
485485 // reapply the Send marker
486- transmute :: < Box < Error > , Box < Error + Send > > ( s)
486+ transmute :: < Box < dyn Error > , Box < dyn Error + Send > > ( s)
487487 } )
488488 }
489489}
490490
491- impl Error + Send + Sync {
491+ impl dyn Error + Send + Sync {
492492 #[ inline]
493493 #[ stable( feature = "error_downcast" , since = "1.3.0" ) ]
494494 /// Attempt to downcast the box to a concrete type.
495495 pub fn downcast < T : Error + ' static > ( self : Box < Self > )
496496 -> 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 {
499499 // 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)
501501 } )
502502 }
503503}
@@ -533,13 +533,13 @@ mod tests {
533533 #[ test]
534534 fn downcasting ( ) {
535535 let mut a = A ;
536- let a = & mut a as & mut ( Error + ' static ) ;
536+ let a = & mut a as & mut ( dyn Error + ' static ) ;
537537 assert_eq ! ( a. downcast_ref:: <A >( ) , Some ( & A ) ) ;
538538 assert_eq ! ( a. downcast_ref:: <B >( ) , None ) ;
539539 assert_eq ! ( a. downcast_mut:: <A >( ) , Some ( & mut A ) ) ;
540540 assert_eq ! ( a. downcast_mut:: <B >( ) , None ) ;
541541
542- let a: Box < Error > = Box :: new ( A ) ;
542+ let a: Box < dyn Error > = Box :: new ( A ) ;
543543 match a. downcast :: < B > ( ) {
544544 Ok ( ..) => panic ! ( "expected error" ) ,
545545 Err ( e) => assert_eq ! ( * e. downcast:: <A >( ) . unwrap( ) , A ) ,
0 commit comments