@@ -188,7 +188,7 @@ impl Error {
188
188
/// If this `Error` was constructed via `new` then this function will
189
189
/// return `Some`, otherwise it will return `None`.
190
190
#[ unstable( feature = "io_error_inner" , reason = "recently added" ) ]
191
- pub fn get_ref ( & self ) -> Option < & ( error:: Error +Send +Sync ) > {
191
+ pub fn get_ref ( & self ) -> Option < & ( error:: Error +Send +Sync + ' static ) > {
192
192
match self . repr {
193
193
Repr :: Os ( ..) => None ,
194
194
Repr :: Custom ( ref c) => Some ( & * c. error ) ,
@@ -201,7 +201,7 @@ impl Error {
201
201
/// If this `Error` was constructed via `new` then this function will
202
202
/// return `Some`, otherwise it will return `None`.
203
203
#[ unstable( feature = "io_error_inner" , reason = "recently added" ) ]
204
- pub fn get_mut ( & mut self ) -> Option < & mut ( error:: Error +Send +Sync ) > {
204
+ pub fn get_mut ( & mut self ) -> Option < & mut ( error:: Error +Send +Sync + ' static ) > {
205
205
match self . repr {
206
206
Repr :: Os ( ..) => None ,
207
207
Repr :: Custom ( ref mut c) => Some ( & mut * c. error ) ,
@@ -264,3 +264,39 @@ fn _assert_error_is_sync_send() {
264
264
fn _is_sync_send < T : Sync +Send > ( ) { }
265
265
_is_sync_send :: < Error > ( ) ;
266
266
}
267
+
268
+ #[ cfg( test) ]
269
+ mod test {
270
+ use prelude:: v1:: * ;
271
+ use super :: { Error , ErrorKind } ;
272
+ use error;
273
+ use error:: Error as error_Error;
274
+ use fmt;
275
+
276
+ #[ test]
277
+ fn test_downcasting ( ) {
278
+ #[ derive( Debug ) ]
279
+ struct TestError ;
280
+
281
+ impl fmt:: Display for TestError {
282
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
283
+ Ok ( ( ) )
284
+ }
285
+ }
286
+
287
+ impl error:: Error for TestError {
288
+ fn description ( & self ) -> & str {
289
+ "asdf"
290
+ }
291
+ }
292
+
293
+ // we have to call all of these UFCS style right now since method
294
+ // resolution won't implicitly drop the Send+Sync bounds
295
+ let mut err = Error :: new ( ErrorKind :: Other , TestError ) ;
296
+ assert ! ( error:: Error :: is:: <TestError >( err. get_ref( ) . unwrap( ) ) ) ;
297
+ assert_eq ! ( "asdf" , err. get_ref( ) . unwrap( ) . description( ) ) ;
298
+ assert ! ( error:: Error :: is:: <TestError >( err. get_mut( ) . unwrap( ) ) ) ;
299
+ let extracted = err. into_inner ( ) . unwrap ( ) ;
300
+ error:: Error :: downcast :: < TestError > ( extracted) . unwrap ( ) ;
301
+ }
302
+ }
0 commit comments