diff --git a/src/librustc_driver/args.rs b/src/librustc_driver/args.rs index 339a10f914044..5e2c43596dbeb 100644 --- a/src/librustc_driver/args.rs +++ b/src/librustc_driver/args.rs @@ -2,7 +2,6 @@ use std::error; use std::fmt; use std::fs; use std::io; -use std::str; pub fn arg_expand(arg: String) -> Result, Error> { if arg.starts_with("@") { @@ -36,8 +35,4 @@ impl fmt::Display for Error { } } -impl error::Error for Error { - fn description(&self) -> &'static str { - "argument error" - } -} +impl error::Error for Error {} diff --git a/src/librustc_error_codes/error_codes/E0638.md b/src/librustc_error_codes/error_codes/E0638.md index 29b7586b07b44..15c952a5640fc 100644 --- a/src/librustc_error_codes/error_codes/E0638.md +++ b/src/librustc_error_codes/error_codes/E0638.md @@ -12,21 +12,23 @@ on it. ```rust,ignore (pseudo-Rust) use std::error::Error as StdError; -#[non_exhaustive] pub enum Error { - Message(String), - Other, +#[non_exhaustive] +pub enum Error { + Message(String), + Other, } -impl StdError for Error { - fn description(&self) -> &str { +impl Display for Error { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { // This will not error, despite being marked as non_exhaustive, as this // enum is defined within the current crate, it can be matched // exhaustively. - match *self { - Message(ref s) => s, - Other => "other or unknown error", - } - } + let display = match self { + Message(s) => s, + Other => "other or unknown error", + }; + formatter.write_str(display) + } } ``` @@ -38,9 +40,9 @@ use mycrate::Error; // This will not error as the non_exhaustive Error enum has been matched with a // wildcard. match error { - Message(ref s) => ..., - Other => ..., - _ => ..., + Message(s) => ..., + Other => ..., + _ => ..., } ``` diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index ae5876848185b..24363704bc8a7 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -251,11 +251,7 @@ impl fmt::Display for ExplicitBug { } } -impl error::Error for ExplicitBug { - fn description(&self) -> &str { - "The parser has encountered an internal bug" - } -} +impl error::Error for ExplicitBug {} pub use diagnostic::{Diagnostic, SubDiagnostic, DiagnosticStyledString, DiagnosticId}; pub use diagnostic_builder::DiagnosticBuilder; diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 0967b25788557..9146349e9a21e 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -200,18 +200,7 @@ impl fmt::Display for ConstEvalError { } } -impl Error for ConstEvalError { - fn description(&self) -> &str { - use self::ConstEvalError::*; - match *self { - NeedsRfc(_) => "this feature needs an rfc before being allowed inside constants", - } - } - - fn cause(&self) -> Option<&dyn Error> { - None - } -} +impl Error for ConstEvalError {} // Extra machine state for CTFE, and the Machine instance pub struct CompileTimeInterpreter<'mir, 'tcx> { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index b5c1a77a38742..479feb00fdba1 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -100,11 +100,7 @@ pub struct Error { pub error: io::Error, } -impl error::Error for Error { - fn description(&self) -> &str { - self.error.description() - } -} +impl error::Error for Error {} impl std::fmt::Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index 95d92f311ed3c..5cba9aa13885d 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -69,15 +69,7 @@ impl fmt::Display for FromHexError { } } -impl error::Error for FromHexError { - fn description(&self) -> &str { - match *self { - InvalidHexCharacter(..) => "invalid character", - InvalidHexLength => "invalid length", - } - } -} - +impl error::Error for FromHexError {} impl FromHex for str { /// Converts any hexadecimal encoded string (literal, `@`, `&`, or `~`) diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index d2e360f5e20fd..2f4dee8d22548 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -338,9 +338,7 @@ impl fmt::Display for DecoderError { } } -impl std::error::Error for DecoderError { - fn description(&self) -> &str { "decoder error" } -} +impl std::error::Error for DecoderError {} impl fmt::Display for EncoderError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -349,9 +347,7 @@ impl fmt::Display for EncoderError { } } -impl std::error::Error for EncoderError { - fn description(&self) -> &str { "encoder error" } -} +impl std::error::Error for EncoderError {} impl From for EncoderError { /// Converts a [`fmt::Error`] into `EncoderError` diff --git a/src/libstd/env.rs b/src/libstd/env.rs index cf71b61b917a7..52eebcfcb94c0 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -284,6 +284,7 @@ impl fmt::Display for VarError { #[stable(feature = "env", since = "1.0.0")] impl Error for VarError { + #[allow(deprecated)] fn description(&self) -> &str { match *self { VarError::NotPresent => "environment variable not found", @@ -526,6 +527,7 @@ impl fmt::Display for JoinPathsError { #[stable(feature = "env", since = "1.0.0")] impl Error for JoinPathsError { + #[allow(deprecated, deprecated_in_future)] fn description(&self) -> &str { self.inner.description() } diff --git a/src/libstd/error.rs b/src/libstd/error.rs index ec1c444bcf8c8..9a0ee4f1b709a 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -45,97 +45,6 @@ use crate::string; /// [`source`]: trait.Error.html#method.source #[stable(feature = "rust1", since = "1.0.0")] pub trait Error: Debug + Display { - /// **This method is soft-deprecated.** - /// - /// Although using it won’t cause compilation warning, - /// new code should use [`Display`] instead - /// and new `impl`s can omit it. - /// - /// To obtain error description as a string, use `to_string()`. - /// - /// [`Display`]: ../fmt/trait.Display.html - /// - /// # Examples - /// - /// ``` - /// match "xc".parse::() { - /// Err(e) => { - /// // Print `e` itself, not `e.description()`. - /// println!("Error: {}", e); - /// } - /// _ => println!("No error"), - /// } - /// ``` - #[stable(feature = "rust1", since = "1.0.0")] - fn description(&self) -> &str { - "description() is deprecated; use Display" - } - - /// The lower-level cause of this error, if any. - /// - /// # Examples - /// - /// ``` - /// use std::error::Error; - /// use std::fmt; - /// - /// #[derive(Debug)] - /// struct SuperError { - /// side: SuperErrorSideKick, - /// } - /// - /// impl fmt::Display for SuperError { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "SuperError is here!") - /// } - /// } - /// - /// impl Error for SuperError { - /// fn description(&self) -> &str { - /// "I'm the superhero of errors" - /// } - /// - /// fn cause(&self) -> Option<&dyn Error> { - /// Some(&self.side) - /// } - /// } - /// - /// #[derive(Debug)] - /// struct SuperErrorSideKick; - /// - /// impl fmt::Display for SuperErrorSideKick { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "SuperErrorSideKick is here!") - /// } - /// } - /// - /// impl Error for SuperErrorSideKick { - /// fn description(&self) -> &str { - /// "I'm SuperError side kick" - /// } - /// } - /// - /// fn get_super_error() -> Result<(), SuperError> { - /// Err(SuperError { side: SuperErrorSideKick }) - /// } - /// - /// fn main() { - /// match get_super_error() { - /// Err(e) => { - /// println!("Error: {}", e.description()); - /// println!("Caused by: {}", e.cause().unwrap()); - /// } - /// _ => println!("No error"), - /// } - /// } - /// ``` - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_deprecated(since = "1.33.0", reason = "replaced by Error::source, which can support \ - downcasting")] - fn cause(&self) -> Option<&dyn Error> { - self.source() - } - /// The lower-level source of this error, if any. /// /// # Examples @@ -156,10 +65,6 @@ pub trait Error: Debug + Display { /// } /// /// impl Error for SuperError { - /// fn description(&self) -> &str { - /// "I'm the superhero of errors" - /// } - /// /// fn source(&self) -> Option<&(dyn Error + 'static)> { /// Some(&self.side) /// } @@ -174,11 +79,7 @@ pub trait Error: Debug + Display { /// } /// } /// - /// impl Error for SuperErrorSideKick { - /// fn description(&self) -> &str { - /// "I'm SuperError side kick" - /// } - /// } + /// impl Error for SuperErrorSideKick {} /// /// fn get_super_error() -> Result<(), SuperError> { /// Err(SuperError { side: SuperErrorSideKick }) @@ -219,6 +120,31 @@ pub trait Error: Debug + Display { fn backtrace(&self) -> Option<&Backtrace> { None } + + /// ``` + /// if let Err(e) = "xc".parse::() { + /// // Print `e` itself, no need for description(). + /// eprintln!("Error: {}", e); + /// } + /// ``` + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_deprecated( + since = "1.41.0", + reason = "use the Display impl or to_string()" + )] + fn description(&self) -> &str { + "description() is deprecated; use Display" + } + + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_deprecated( + since = "1.33.0", + reason = "replaced by Error::source, which can support downcasting" + )] + #[allow(missing_docs)] + fn cause(&self) -> Option<&dyn Error> { + self.source() + } } mod private { @@ -251,11 +177,7 @@ impl<'a, E: Error + 'a> From for Box { /// } /// } /// - /// impl Error for AnError { - /// fn description(&self) -> &str { - /// "Description of an error" - /// } - /// } + /// impl Error for AnError {} /// /// let an_error = AnError; /// assert!(0 == mem::size_of_val(&an_error)); @@ -290,11 +212,7 @@ impl<'a, E: Error + Send + Sync + 'a> From for Box &str { - /// "Description of an error" - /// } - /// } + /// impl Error for AnError {} /// /// unsafe impl Send for AnError {} /// @@ -332,6 +250,7 @@ impl From for Box { struct StringError(String); impl Error for StringError { + #[allow(deprecated)] fn description(&self) -> &str { &self.0 } } @@ -466,44 +385,32 @@ impl<'a> From> for Box { } #[stable(feature = "never_type", since = "1.41.0")] -impl Error for ! { - fn description(&self) -> &str { *self } -} +impl Error for ! {} #[unstable(feature = "allocator_api", reason = "the precise API and guarantees it provides may be tweaked.", issue = "32838")] -impl Error for AllocErr { - fn description(&self) -> &str { - "memory allocation failed" - } -} +impl Error for AllocErr {} #[unstable(feature = "allocator_api", reason = "the precise API and guarantees it provides may be tweaked.", issue = "32838")] -impl Error for LayoutErr { - fn description(&self) -> &str { - "invalid parameters to Layout::from_size_align" - } -} +impl Error for LayoutErr {} #[unstable(feature = "allocator_api", reason = "the precise API and guarantees it provides may be tweaked.", issue = "32838")] -impl Error for CannotReallocInPlace { - fn description(&self) -> &str { - CannotReallocInPlace::description(self) - } -} +impl Error for CannotReallocInPlace {} #[stable(feature = "rust1", since = "1.0.0")] impl Error for str::ParseBoolError { + #[allow(deprecated)] fn description(&self) -> &str { "failed to parse bool" } } #[stable(feature = "rust1", since = "1.0.0")] impl Error for str::Utf8Error { + #[allow(deprecated)] fn description(&self) -> &str { "invalid utf-8: corrupt contents" } @@ -511,6 +418,7 @@ impl Error for str::Utf8Error { #[stable(feature = "rust1", since = "1.0.0")] impl Error for num::ParseIntError { + #[allow(deprecated)] fn description(&self) -> &str { self.__description() } @@ -518,6 +426,7 @@ impl Error for num::ParseIntError { #[stable(feature = "try_from", since = "1.34.0")] impl Error for num::TryFromIntError { + #[allow(deprecated)] fn description(&self) -> &str { self.__description() } @@ -525,6 +434,7 @@ impl Error for num::TryFromIntError { #[stable(feature = "try_from", since = "1.34.0")] impl Error for array::TryFromSliceError { + #[allow(deprecated)] fn description(&self) -> &str { self.__description() } @@ -532,6 +442,7 @@ impl Error for array::TryFromSliceError { #[stable(feature = "rust1", since = "1.0.0")] impl Error for num::ParseFloatError { + #[allow(deprecated)] fn description(&self) -> &str { self.__description() } @@ -539,6 +450,7 @@ impl Error for num::ParseFloatError { #[stable(feature = "rust1", since = "1.0.0")] impl Error for string::FromUtf8Error { + #[allow(deprecated)] fn description(&self) -> &str { "invalid utf-8" } @@ -546,6 +458,7 @@ impl Error for string::FromUtf8Error { #[stable(feature = "rust1", since = "1.0.0")] impl Error for string::FromUtf16Error { + #[allow(deprecated)] fn description(&self) -> &str { "invalid utf-16" } @@ -553,6 +466,7 @@ impl Error for string::FromUtf16Error { #[stable(feature = "decode_utf16", since = "1.9.0")] impl Error for char::DecodeUtf16Error { + #[allow(deprecated)] fn description(&self) -> &str { "unpaired surrogate found" } @@ -560,6 +474,7 @@ impl Error for char::DecodeUtf16Error { #[stable(feature = "box_error", since = "1.8.0")] impl Error for Box { + #[allow(deprecated, deprecated_in_future)] fn description(&self) -> &str { Error::description(&**self) } @@ -576,6 +491,7 @@ impl Error for Box { #[stable(feature = "fmt_error", since = "1.11.0")] impl Error for fmt::Error { + #[allow(deprecated)] fn description(&self) -> &str { "an error occurred when formatting an argument" } @@ -583,6 +499,7 @@ impl Error for fmt::Error { #[stable(feature = "try_borrow", since = "1.13.0")] impl Error for cell::BorrowError { + #[allow(deprecated)] fn description(&self) -> &str { "already mutably borrowed" } @@ -590,6 +507,7 @@ impl Error for cell::BorrowError { #[stable(feature = "try_borrow", since = "1.13.0")] impl Error for cell::BorrowMutError { + #[allow(deprecated)] fn description(&self) -> &str { "already borrowed" } @@ -597,6 +515,7 @@ impl Error for cell::BorrowMutError { #[stable(feature = "try_from", since = "1.34.0")] impl Error for char::CharTryFromError { + #[allow(deprecated)] fn description(&self) -> &str { "converted integer out of range for `char`" } @@ -604,6 +523,7 @@ impl Error for char::CharTryFromError { #[stable(feature = "char_from_str", since = "1.20.0")] impl Error for char::ParseCharError { + #[allow(deprecated)] fn description(&self) -> &str { self.__description() } @@ -849,12 +769,8 @@ mod tests { } } - impl Error for A { - fn description(&self) -> &str { "A-desc" } - } - impl Error for B { - fn description(&self) -> &str { "A-desc" } - } + impl Error for A {} + impl Error for B {} #[test] fn downcasting() { diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 6dcda98631014..0cbbe4cbbe5a1 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -875,6 +875,7 @@ impl NulError { #[stable(feature = "rust1", since = "1.0.0")] impl Error for NulError { + #[allow(deprecated)] fn description(&self) -> &str { "nul byte found in data" } } @@ -899,6 +900,7 @@ impl From for io::Error { #[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")] impl Error for FromBytesWithNulError { + #[allow(deprecated)] fn description(&self) -> &str { match self.kind { FromBytesWithNulErrorKind::InteriorNul(..) => @@ -911,6 +913,7 @@ impl Error for FromBytesWithNulError { #[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")] impl fmt::Display for FromBytesWithNulError { + #[allow(deprecated, deprecated_in_future)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(self.description())?; if let FromBytesWithNulErrorKind::InteriorNul(pos) = self.kind { @@ -939,6 +942,7 @@ impl IntoStringError { #[stable(feature = "cstring_into", since = "1.7.0")] impl Error for IntoStringError { + #[allow(deprecated)] fn description(&self) -> &str { "C string contained non-utf8 bytes" } @@ -950,6 +954,7 @@ impl Error for IntoStringError { #[stable(feature = "cstring_into", since = "1.7.0")] impl fmt::Display for IntoStringError { + #[allow(deprecated, deprecated_in_future)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.description().fmt(f) } diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 8e81b292f6fa3..bce871aee8dce 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -752,6 +752,7 @@ impl From> for Error { #[stable(feature = "rust1", since = "1.0.0")] impl error::Error for IntoInnerError { + #[allow(deprecated, deprecated_in_future)] fn description(&self) -> &str { error::Error::description(self.error()) } diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index c20bd3097b27d..3b55d9b900235 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -402,9 +402,7 @@ impl Error { /// } /// } /// - /// impl error::Error for MyError { - /// fn description(&self) -> &str { &self.v } - /// } + /// impl error::Error for MyError {} /// /// impl Display for MyError { /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -536,6 +534,7 @@ impl fmt::Display for Error { #[stable(feature = "rust1", since = "1.0.0")] impl error::Error for Error { + #[allow(deprecated, deprecated_in_future)] fn description(&self) -> &str { match self.repr { Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), @@ -605,22 +604,18 @@ mod test { struct TestError; impl fmt::Display for TestError { - fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { - Ok(()) + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("asdf") } } - impl error::Error for TestError { - fn description(&self) -> &str { - "asdf" - } - } + impl error::Error for TestError {} // we have to call all of these UFCS style right now since method // resolution won't implicitly drop the Send+Sync bounds let mut err = Error::new(ErrorKind::Other, TestError); assert!(err.get_ref().unwrap().is::()); - assert_eq!("asdf", err.get_ref().unwrap().description()); + assert_eq!("asdf", err.get_ref().unwrap().to_string()); assert!(err.get_mut().unwrap().is::()); let extracted = err.into_inner().unwrap(); extracted.downcast::().unwrap(); diff --git a/src/libstd/net/parser.rs b/src/libstd/net/parser.rs index 8106d1c3315aa..313f07621045d 100644 --- a/src/libstd/net/parser.rs +++ b/src/libstd/net/parser.rs @@ -378,6 +378,7 @@ pub struct AddrParseError(()); #[stable(feature = "addr_parse_error_error", since = "1.4.0")] impl fmt::Display for AddrParseError { + #[allow(deprecated, deprecated_in_future)] fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.write_str(self.description()) } @@ -385,6 +386,7 @@ impl fmt::Display for AddrParseError { #[stable(feature = "addr_parse_error_error", since = "1.4.0")] impl Error for AddrParseError { + #[allow(deprecated)] fn description(&self) -> &str { "invalid IP address syntax" } diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 42bca0a9575b3..580ff1610ac83 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -2786,6 +2786,7 @@ impl_cmp_os_str!(Cow<'a, Path>, OsString); #[stable(since = "1.7.0", feature = "strip_prefix")] impl fmt::Display for StripPrefixError { + #[allow(deprecated, deprecated_in_future)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.description().fmt(f) } @@ -2793,6 +2794,7 @@ impl fmt::Display for StripPrefixError { #[stable(since = "1.7.0", feature = "strip_prefix")] impl Error for StripPrefixError { + #[allow(deprecated)] fn description(&self) -> &str { "prefix not found" } diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 2831bbcb88d2e..0e334c191e7b9 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -1550,6 +1550,7 @@ impl fmt::Display for SendError { #[stable(feature = "rust1", since = "1.0.0")] impl error::Error for SendError { + #[allow(deprecated)] fn description(&self) -> &str { "sending on a closed channel" } @@ -1577,6 +1578,7 @@ impl fmt::Display for TrySendError { #[stable(feature = "rust1", since = "1.0.0")] impl error::Error for TrySendError { + #[allow(deprecated)] fn description(&self) -> &str { match *self { TrySendError::Full(..) => "sending on a full channel", @@ -1603,6 +1605,7 @@ impl fmt::Display for RecvError { #[stable(feature = "rust1", since = "1.0.0")] impl error::Error for RecvError { + #[allow(deprecated)] fn description(&self) -> &str { "receiving on a closed channel" } @@ -1620,6 +1623,7 @@ impl fmt::Display for TryRecvError { #[stable(feature = "rust1", since = "1.0.0")] impl error::Error for TryRecvError { + #[allow(deprecated)] fn description(&self) -> &str { match *self { TryRecvError::Empty => "receiving on an empty channel", @@ -1649,6 +1653,7 @@ impl fmt::Display for RecvTimeoutError { #[stable(feature = "mpsc_recv_timeout_error", since = "1.15.0")] impl error::Error for RecvTimeoutError { + #[allow(deprecated)] fn description(&self) -> &str { match *self { RecvTimeoutError::Timeout => "timed out waiting on channel", diff --git a/src/libstd/sys/cloudabi/shims/os.rs b/src/libstd/sys/cloudabi/shims/os.rs index 944b9525b3b60..779e6d54b7c9f 100644 --- a/src/libstd/sys/cloudabi/shims/os.rs +++ b/src/libstd/sys/cloudabi/shims/os.rs @@ -63,6 +63,7 @@ impl fmt::Display for JoinPathsError { } impl StdError for JoinPathsError { + #[allow(deprecated)] fn description(&self) -> &str { "not supported on CloudABI yet" } diff --git a/src/libstd/sys/hermit/os.rs b/src/libstd/sys/hermit/os.rs index ad63b0e0c1318..5999fdd4f8d58 100644 --- a/src/libstd/sys/hermit/os.rs +++ b/src/libstd/sys/hermit/os.rs @@ -61,6 +61,7 @@ impl fmt::Display for JoinPathsError { } impl StdError for JoinPathsError { + #[allow(deprecated)] fn description(&self) -> &str { "not supported on hermit yet" } diff --git a/src/libstd/sys/sgx/net.rs b/src/libstd/sys/sgx/net.rs index f36687b4d3d58..bd0652ab4649a 100644 --- a/src/libstd/sys/sgx/net.rs +++ b/src/libstd/sys/sgx/net.rs @@ -440,6 +440,7 @@ pub struct NonIpSockAddr { } impl error::Error for NonIpSockAddr { + #[allow(deprecated)] fn description(&self) -> &str { "Failed to convert address to SocketAddr" } diff --git a/src/libstd/sys/sgx/os.rs b/src/libstd/sys/sgx/os.rs index 2c5b31342199a..6ed7a2f20444e 100644 --- a/src/libstd/sys/sgx/os.rs +++ b/src/libstd/sys/sgx/os.rs @@ -66,6 +66,7 @@ impl fmt::Display for JoinPathsError { } impl StdError for JoinPathsError { + #[allow(deprecated)] fn description(&self) -> &str { "not supported in SGX yet" } diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 10cdb25999ca9..c206432a37963 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -202,6 +202,7 @@ impl fmt::Display for JoinPathsError { } impl StdError for JoinPathsError { + #[allow(deprecated)] fn description(&self) -> &str { "failed to join paths" } } diff --git a/src/libstd/sys/vxworks/os.rs b/src/libstd/sys/vxworks/os.rs index baa6c425d2e7f..18dc38dbf9969 100644 --- a/src/libstd/sys/vxworks/os.rs +++ b/src/libstd/sys/vxworks/os.rs @@ -169,6 +169,7 @@ impl fmt::Display for JoinPathsError { } impl StdError for JoinPathsError { + #[allow(deprecated)] fn description(&self) -> &str { "failed to join paths" } } diff --git a/src/libstd/sys/wasi/os.rs b/src/libstd/sys/wasi/os.rs index 338fbe8976514..44a08a2f0585d 100644 --- a/src/libstd/sys/wasi/os.rs +++ b/src/libstd/sys/wasi/os.rs @@ -78,6 +78,7 @@ impl fmt::Display for JoinPathsError { } impl StdError for JoinPathsError { + #[allow(deprecated)] fn description(&self) -> &str { "not supported on wasm yet" } diff --git a/src/libstd/sys/wasm/os.rs b/src/libstd/sys/wasm/os.rs index 193c3892743c4..91afdc8a5a0cc 100644 --- a/src/libstd/sys/wasm/os.rs +++ b/src/libstd/sys/wasm/os.rs @@ -53,6 +53,7 @@ impl fmt::Display for JoinPathsError { } impl StdError for JoinPathsError { + #[allow(deprecated)] fn description(&self) -> &str { "not supported on wasm yet" } diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 8631e50cf3888..e0a1d2f4c0e20 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -225,6 +225,7 @@ impl fmt::Display for JoinPathsError { } impl StdError for JoinPathsError { + #[allow(deprecated)] fn description(&self) -> &str { "failed to join paths" } diff --git a/src/libstd/sys_common/poison.rs b/src/libstd/sys_common/poison.rs index 0157b952996ac..285851d631ae7 100644 --- a/src/libstd/sys_common/poison.rs +++ b/src/libstd/sys_common/poison.rs @@ -148,6 +148,7 @@ impl fmt::Display for PoisonError { #[stable(feature = "rust1", since = "1.0.0")] impl Error for PoisonError { + #[allow(deprecated)] fn description(&self) -> &str { "poisoned lock: another task failed inside" } @@ -239,6 +240,7 @@ impl fmt::Display for TryLockError { #[stable(feature = "rust1", since = "1.0.0")] impl Error for TryLockError { + #[allow(deprecated, deprecated_in_future)] fn description(&self) -> &str { match *self { TryLockError::Poisoned(ref p) => p.description(), @@ -246,6 +248,7 @@ impl Error for TryLockError { } } + #[allow(deprecated)] fn cause(&self) -> Option<&dyn Error> { match *self { TryLockError::Poisoned(ref p) => Some(p), diff --git a/src/libstd/time.rs b/src/libstd/time.rs index e1ae01b602a8d..03f1ef0000a34 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -621,6 +621,7 @@ impl SystemTimeError { #[stable(feature = "time2", since = "1.8.0")] impl Error for SystemTimeError { + #[allow(deprecated)] fn description(&self) -> &str { "other time was not earlier than self" } diff --git a/src/libsyntax_pos/fatal_error.rs b/src/libsyntax_pos/fatal_error.rs index cf7c677d59d95..718c0ddbc63ea 100644 --- a/src/libsyntax_pos/fatal_error.rs +++ b/src/libsyntax_pos/fatal_error.rs @@ -23,8 +23,4 @@ impl std::fmt::Display for FatalError { } } -impl std::error::Error for FatalError { - fn description(&self) -> &str { - "The parser has encountered a fatal error" - } -} +impl std::error::Error for FatalError {} diff --git a/src/libterm/terminfo/mod.rs b/src/libterm/terminfo/mod.rs index be90195065eb7..3cd8232e43550 100644 --- a/src/libterm/terminfo/mod.rs +++ b/src/libterm/terminfo/mod.rs @@ -42,14 +42,10 @@ pub enum Error { } impl error::Error for Error { - fn description(&self) -> &str { - "failed to create TermInfo" - } - - fn cause(&self) -> Option<&dyn error::Error> { + fn source(&self) -> Option<&(dyn error::Error + 'static)> { use Error::*; - match *self { - IoError(ref e) => Some(e), + match self { + IoError(e) => Some(e), _ => None, } } diff --git a/src/tools/error_index_generator/main.rs b/src/tools/error_index_generator/main.rs index 31a802706cba4..a7b12323cf748 100644 --- a/src/tools/error_index_generator/main.rs +++ b/src/tools/error_index_generator/main.rs @@ -255,7 +255,7 @@ fn main() { main_with_result(format, &dst) }); if let Err(e) = result { - panic!("{}", e.description()); + panic!("{}", e.to_string()); } }