@@ -74,7 +74,7 @@ enum Repr {
74
74
#[ derive( Debug ) ]
75
75
struct Custom {
76
76
kind : ErrorKind ,
77
- error : Box < dyn error :: Error + Send + Sync > ,
77
+ error : String ,
78
78
}
79
79
80
80
/// A list specifying general categories of I/O error.
@@ -177,6 +177,12 @@ pub enum ErrorKind {
177
177
/// read.
178
178
#[ stable( feature = "read_exact" , since = "1.6.0" ) ]
179
179
UnexpectedEof ,
180
+
181
+ /// A marker variant that tells the compiler that users of this enum cannot
182
+ /// match it exhaustively.
183
+ #[ doc( hidden) ]
184
+ #[ stable( feature = "read_exact" , since = "1.6.0" ) ]
185
+ __Nonexhaustive,
180
186
}
181
187
182
188
impl ErrorKind {
@@ -200,6 +206,7 @@ impl ErrorKind {
200
206
ErrorKind :: Interrupted => "operation interrupted" ,
201
207
ErrorKind :: Other => "other os error" ,
202
208
ErrorKind :: UnexpectedEof => "unexpected end of file" ,
209
+ _ => "unknown error" ,
203
210
}
204
211
}
205
212
}
@@ -249,33 +256,15 @@ impl Error {
249
256
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
250
257
pub fn new < E > ( kind : ErrorKind , error : E ) -> Error
251
258
where
252
- E : Into < Box < dyn error :: Error + Send + Sync > > ,
259
+ E : Into < String > ,
253
260
{
254
261
Self :: _new ( kind, error. into ( ) )
255
262
}
256
263
257
- fn _new ( kind : ErrorKind , error : Box < dyn error :: Error + Send + Sync > ) -> Error {
264
+ fn _new ( kind : ErrorKind , error : String ) -> Error {
258
265
Error { repr : Repr :: Custom ( Box :: new ( Custom { kind, error } ) ) }
259
266
}
260
267
261
- /// Returns an error representing the last OS error which occurred.
262
- ///
263
- /// This function reads the value of `errno` for the target platform (e.g.
264
- /// `GetLastError` on Windows) and will return a corresponding instance of
265
- /// [`Error`] for the error code.
266
- ///
267
- /// # Examples
268
- ///
269
- /// ```
270
- /// use std::io::Error;
271
- ///
272
- /// println!("last OS error: {:?}", Error::last_os_error());
273
- /// ```
274
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
275
- pub fn last_os_error ( ) -> Error {
276
- Error :: from_raw_os_error ( sys:: os:: errno ( ) as i32 )
277
- }
278
-
279
268
/// Creates a new instance of an [`Error`] from a particular OS error code.
280
269
///
281
270
/// # Examples
@@ -372,11 +361,11 @@ impl Error {
372
361
/// }
373
362
/// ```
374
363
#[ stable( feature = "io_error_inner" , since = "1.3.0" ) ]
375
- pub fn get_ref ( & self ) -> Option < & ( dyn error :: Error + Send + Sync + ' static ) > {
364
+ pub fn get_ref ( & self ) -> Option < & String > {
376
365
match self . repr {
377
366
Repr :: Os ( ..) => None ,
378
367
Repr :: Simple ( ..) => None ,
379
- Repr :: Custom ( ref c) => Some ( & * c. error ) ,
368
+ Repr :: Custom ( ref c) => Some ( & c. error ) ,
380
369
}
381
370
}
382
371
@@ -443,11 +432,11 @@ impl Error {
443
432
/// }
444
433
/// ```
445
434
#[ stable( feature = "io_error_inner" , since = "1.3.0" ) ]
446
- pub fn get_mut ( & mut self ) -> Option < & mut ( dyn error :: Error + Send + Sync + ' static ) > {
435
+ pub fn get_mut ( & mut self ) -> Option < & mut String > {
447
436
match self . repr {
448
437
Repr :: Os ( ..) => None ,
449
438
Repr :: Simple ( ..) => None ,
450
- Repr :: Custom ( ref mut c) => Some ( & mut * c. error ) ,
439
+ Repr :: Custom ( ref mut c) => Some ( & mut c. error ) ,
451
440
}
452
441
}
453
442
@@ -479,7 +468,7 @@ impl Error {
479
468
/// }
480
469
/// ```
481
470
#[ stable( feature = "io_error_inner" , since = "1.3.0" ) ]
482
- pub fn into_inner ( self ) -> Option < Box < dyn error :: Error + Send + Sync > > {
471
+ pub fn into_inner ( self ) -> Option < String > {
483
472
match self . repr {
484
473
Repr :: Os ( ..) => None ,
485
474
Repr :: Simple ( ..) => None ,
@@ -508,7 +497,7 @@ impl Error {
508
497
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
509
498
pub fn kind ( & self ) -> ErrorKind {
510
499
match self . repr {
511
- Repr :: Os ( code ) => sys :: decode_error_kind ( code ) ,
500
+ Repr :: Os ( _code ) => ErrorKind :: Other ,
512
501
Repr :: Custom ( ref c) => c. kind ,
513
502
Repr :: Simple ( kind) => kind,
514
503
}
@@ -521,8 +510,6 @@ impl fmt::Debug for Repr {
521
510
Repr :: Os ( code) => fmt
522
511
. debug_struct ( "Os" )
523
512
. field ( "code" , & code)
524
- . field ( "kind" , & sys:: decode_error_kind ( code) )
525
- . field ( "message" , & sys:: os:: error_string ( code) )
526
513
. finish ( ) ,
527
514
Repr :: Custom ( ref c) => fmt:: Debug :: fmt ( & c, fmt) ,
528
515
Repr :: Simple ( kind) => fmt. debug_tuple ( "Kind" ) . field ( & kind) . finish ( ) ,
@@ -535,43 +522,14 @@ impl fmt::Display for Error {
535
522
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
536
523
match self . repr {
537
524
Repr :: Os ( code) => {
538
- let detail = sys:: os:: error_string ( code) ;
539
- write ! ( fmt, "{} (os error {})" , detail, code)
525
+ write ! ( fmt, "os error {}" , code)
540
526
}
541
527
Repr :: Custom ( ref c) => c. error . fmt ( fmt) ,
542
528
Repr :: Simple ( kind) => write ! ( fmt, "{}" , kind. as_str( ) ) ,
543
529
}
544
530
}
545
531
}
546
532
547
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
548
- impl error:: Error for Error {
549
- #[ allow( deprecated, deprecated_in_future) ]
550
- fn description ( & self ) -> & str {
551
- match self . repr {
552
- Repr :: Os ( ..) | Repr :: Simple ( ..) => self . kind ( ) . as_str ( ) ,
553
- Repr :: Custom ( ref c) => c. error . description ( ) ,
554
- }
555
- }
556
-
557
- #[ allow( deprecated) ]
558
- fn cause ( & self ) -> Option < & dyn error:: Error > {
559
- match self . repr {
560
- Repr :: Os ( ..) => None ,
561
- Repr :: Simple ( ..) => None ,
562
- Repr :: Custom ( ref c) => c. error . cause ( ) ,
563
- }
564
- }
565
-
566
- fn source ( & self ) -> Option < & ( dyn error:: Error + ' static ) > {
567
- match self . repr {
568
- Repr :: Os ( ..) => None ,
569
- Repr :: Simple ( ..) => None ,
570
- Repr :: Custom ( ref c) => c. error . source ( ) ,
571
- }
572
- }
573
- }
574
-
575
533
fn _assert_error_is_sync_send ( ) {
576
534
fn _is_sync_send < T : Sync + Send > ( ) { }
577
535
_is_sync_send :: < Error > ( ) ;
0 commit comments