@@ -74,7 +74,7 @@ enum Repr {
7474#[ derive( Debug ) ]
7575struct Custom {
7676 kind : ErrorKind ,
77- error : Box < dyn error :: Error + Send + Sync > ,
77+ error : String ,
7878}
7979
8080/// A list specifying general categories of I/O error.
@@ -177,6 +177,12 @@ pub enum ErrorKind {
177177 /// read.
178178 #[ stable( feature = "read_exact" , since = "1.6.0" ) ]
179179 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,
180186}
181187
182188impl ErrorKind {
@@ -200,6 +206,7 @@ impl ErrorKind {
200206 ErrorKind :: Interrupted => "operation interrupted" ,
201207 ErrorKind :: Other => "other os error" ,
202208 ErrorKind :: UnexpectedEof => "unexpected end of file" ,
209+ _ => "unknown error" ,
203210 }
204211 }
205212}
@@ -249,33 +256,15 @@ impl Error {
249256 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
250257 pub fn new < E > ( kind : ErrorKind , error : E ) -> Error
251258 where
252- E : Into < Box < dyn error :: Error + Send + Sync > > ,
259+ E : Into < String > ,
253260 {
254261 Self :: _new ( kind, error. into ( ) )
255262 }
256263
257- fn _new ( kind : ErrorKind , error : Box < dyn error :: Error + Send + Sync > ) -> Error {
264+ fn _new ( kind : ErrorKind , error : String ) -> Error {
258265 Error { repr : Repr :: Custom ( Box :: new ( Custom { kind, error } ) ) }
259266 }
260267
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-
279268 /// Creates a new instance of an [`Error`] from a particular OS error code.
280269 ///
281270 /// # Examples
@@ -372,11 +361,11 @@ impl Error {
372361 /// }
373362 /// ```
374363 #[ 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 > {
376365 match self . repr {
377366 Repr :: Os ( ..) => None ,
378367 Repr :: Simple ( ..) => None ,
379- Repr :: Custom ( ref c) => Some ( & * c. error ) ,
368+ Repr :: Custom ( ref c) => Some ( & c. error ) ,
380369 }
381370 }
382371
@@ -443,11 +432,11 @@ impl Error {
443432 /// }
444433 /// ```
445434 #[ 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 > {
447436 match self . repr {
448437 Repr :: Os ( ..) => None ,
449438 Repr :: Simple ( ..) => None ,
450- Repr :: Custom ( ref mut c) => Some ( & mut * c. error ) ,
439+ Repr :: Custom ( ref mut c) => Some ( & mut c. error ) ,
451440 }
452441 }
453442
@@ -479,7 +468,7 @@ impl Error {
479468 /// }
480469 /// ```
481470 #[ 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 > {
483472 match self . repr {
484473 Repr :: Os ( ..) => None ,
485474 Repr :: Simple ( ..) => None ,
@@ -508,7 +497,7 @@ impl Error {
508497 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
509498 pub fn kind ( & self ) -> ErrorKind {
510499 match self . repr {
511- Repr :: Os ( code ) => sys :: decode_error_kind ( code ) ,
500+ Repr :: Os ( _code ) => ErrorKind :: Other ,
512501 Repr :: Custom ( ref c) => c. kind ,
513502 Repr :: Simple ( kind) => kind,
514503 }
@@ -521,8 +510,6 @@ impl fmt::Debug for Repr {
521510 Repr :: Os ( code) => fmt
522511 . debug_struct ( "Os" )
523512 . field ( "code" , & code)
524- . field ( "kind" , & sys:: decode_error_kind ( code) )
525- . field ( "message" , & sys:: os:: error_string ( code) )
526513 . finish ( ) ,
527514 Repr :: Custom ( ref c) => fmt:: Debug :: fmt ( & c, fmt) ,
528515 Repr :: Simple ( kind) => fmt. debug_tuple ( "Kind" ) . field ( & kind) . finish ( ) ,
@@ -535,43 +522,14 @@ impl fmt::Display for Error {
535522 fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
536523 match self . repr {
537524 Repr :: Os ( code) => {
538- let detail = sys:: os:: error_string ( code) ;
539- write ! ( fmt, "{} (os error {})" , detail, code)
525+ write ! ( fmt, "os error {}" , code)
540526 }
541527 Repr :: Custom ( ref c) => c. error . fmt ( fmt) ,
542528 Repr :: Simple ( kind) => write ! ( fmt, "{}" , kind. as_str( ) ) ,
543529 }
544530 }
545531}
546532
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-
575533fn _assert_error_is_sync_send ( ) {
576534 fn _is_sync_send < T : Sync + Send > ( ) { }
577535 _is_sync_send :: < Error > ( ) ;
0 commit comments