Auto merge of #66919 - dtolnay:description, r=KodrAus

Deprecate Error::description for real

`description` has been documented as soft-deprecated since 1.27.0 (17 months ago). There is no longer any reason to call it or implement it.

This PR:

- adds `#[rustc_deprecated(since = "1.41.0")]` to `Error::description`;
- moves `description` (and `cause`, which is also deprecated) below the `source` and `backtrace` methods in the Error trait;
- reduces documentation of `description` and `cause` to take up much less vertical real estate in rustdocs, while preserving the example that shows how to render errors without needing to call `description`;
- removes the description function of all *currently unstable* Error impls in the standard library;
- marks `#[allow(deprecated)]` the description function of all *stable* Error impls in the standard library;
- replaces miscellaneous uses of `description` in example code and the compiler.

---

![description](https://user-images.githubusercontent.com/1940490/69910369-3bbaca80-13bf-11ea-94f7-2fe27a7ea333.png)
This commit is contained in:
bors 2019-12-25 21:10:49 +00:00
commit bbf13723bc
30 changed files with 107 additions and 200 deletions

View File

@ -2,7 +2,6 @@ use std::error;
use std::fmt; use std::fmt;
use std::fs; use std::fs;
use std::io; use std::io;
use std::str;
pub fn arg_expand(arg: String) -> Result<Vec<String>, Error> { pub fn arg_expand(arg: String) -> Result<Vec<String>, Error> {
if arg.starts_with("@") { if arg.starts_with("@") {
@ -36,8 +35,4 @@ impl fmt::Display for Error {
} }
} }
impl error::Error for Error { impl error::Error for Error {}
fn description(&self) -> &'static str {
"argument error"
}
}

View File

@ -10,23 +10,23 @@ For example, in the below example, since the enum is marked as
on it. on it.
```rust,ignore (pseudo-Rust) ```rust,ignore (pseudo-Rust)
use std::error::Error as StdError; #[non_exhaustive]
pub enum Error {
#[non_exhaustive] pub enum Error { Message(String),
Message(String), Other,
Other,
} }
impl StdError for Error { impl Display for Error {
fn description(&self) -> &str { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
// This will not error, despite being marked as non_exhaustive, as this // This will not error, despite being marked as non_exhaustive, as this
// enum is defined within the current crate, it can be matched // enum is defined within the current crate, it can be matched
// exhaustively. // exhaustively.
match *self { let display = match self {
Message(ref s) => s, Message(s) => s,
Other => "other or unknown error", Other => "other or unknown error",
} };
} formatter.write_str(display)
}
} }
``` ```
@ -38,9 +38,9 @@ use mycrate::Error;
// This will not error as the non_exhaustive Error enum has been matched with a // This will not error as the non_exhaustive Error enum has been matched with a
// wildcard. // wildcard.
match error { match error {
Message(ref s) => ..., Message(s) => ...,
Other => ..., Other => ...,
_ => ..., _ => ...,
} }
``` ```

View File

@ -253,11 +253,7 @@ impl fmt::Display for ExplicitBug {
} }
} }
impl error::Error for ExplicitBug { impl error::Error for ExplicitBug {}
fn description(&self) -> &str {
"The parser has encountered an internal bug"
}
}
pub use diagnostic::{Diagnostic, DiagnosticId, DiagnosticStyledString, SubDiagnostic}; pub use diagnostic::{Diagnostic, DiagnosticId, DiagnosticStyledString, SubDiagnostic};
pub use diagnostic_builder::DiagnosticBuilder; pub use diagnostic_builder::DiagnosticBuilder;

View File

@ -197,19 +197,7 @@ impl fmt::Display for ConstEvalError {
} }
} }
impl Error 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",
ConstAccessesStatic => "constant accesses static",
}
}
fn cause(&self) -> Option<&dyn Error> {
None
}
}
// Extra machine state for CTFE, and the Machine instance // Extra machine state for CTFE, and the Machine instance
pub struct CompileTimeInterpreter<'mir, 'tcx> { pub struct CompileTimeInterpreter<'mir, 'tcx> {

View File

@ -98,11 +98,7 @@ pub struct Error {
pub error: io::Error, pub error: io::Error,
} }
impl error::Error for Error { impl error::Error for Error {}
fn description(&self) -> &str {
self.error.description()
}
}
impl std::fmt::Display for Error { impl std::fmt::Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {

View File

@ -68,14 +68,7 @@ impl fmt::Display for FromHexError {
} }
} }
impl error::Error for FromHexError { impl error::Error for FromHexError {}
fn description(&self) -> &str {
match *self {
InvalidHexCharacter(..) => "invalid character",
InvalidHexLength => "invalid length",
}
}
}
impl FromHex for str { impl FromHex for str {
/// Converts any hexadecimal encoded string (literal, `@`, `&`, or `~`) /// Converts any hexadecimal encoded string (literal, `@`, `&`, or `~`)

View File

@ -345,11 +345,7 @@ impl fmt::Display for DecoderError {
} }
} }
impl std::error::Error for DecoderError { impl std::error::Error for DecoderError {}
fn description(&self) -> &str {
"decoder error"
}
}
impl fmt::Display for EncoderError { impl fmt::Display for EncoderError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -358,11 +354,7 @@ impl fmt::Display for EncoderError {
} }
} }
impl std::error::Error for EncoderError { impl std::error::Error for EncoderError {}
fn description(&self) -> &str {
"encoder error"
}
}
impl From<fmt::Error> for EncoderError { impl From<fmt::Error> for EncoderError {
/// Converts a [`fmt::Error`] into `EncoderError` /// Converts a [`fmt::Error`] into `EncoderError`

View File

@ -284,6 +284,7 @@ impl fmt::Display for VarError {
#[stable(feature = "env", since = "1.0.0")] #[stable(feature = "env", since = "1.0.0")]
impl Error for VarError { impl Error for VarError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
match *self { match *self {
VarError::NotPresent => "environment variable not found", VarError::NotPresent => "environment variable not found",
@ -526,6 +527,7 @@ impl fmt::Display for JoinPathsError {
#[stable(feature = "env", since = "1.0.0")] #[stable(feature = "env", since = "1.0.0")]
impl Error for JoinPathsError { impl Error for JoinPathsError {
#[allow(deprecated, deprecated_in_future)]
fn description(&self) -> &str { fn description(&self) -> &str {
self.inner.description() self.inner.description()
} }

View File

@ -45,92 +45,6 @@ use crate::string;
/// [`source`]: trait.Error.html#method.source /// [`source`]: trait.Error.html#method.source
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub trait Error: Debug + Display { pub trait Error: Debug + Display {
/// **This method is soft-deprecated.**
///
/// Although using it wont 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::<u32>() {
/// 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 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 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. /// The lower-level source of this error, if any.
/// ///
/// # Examples /// # Examples
@ -213,6 +127,28 @@ pub trait Error: Debug + Display {
fn backtrace(&self) -> Option<&Backtrace> { fn backtrace(&self) -> Option<&Backtrace> {
None None
} }
/// ```
/// if let Err(e) = "xc".parse::<u32>() {
/// // 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 { mod private {
@ -318,6 +254,7 @@ impl From<String> for Box<dyn Error + Send + Sync> {
struct StringError(String); struct StringError(String);
impl Error for StringError { impl Error for StringError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
&self.0 &self.0
} }
@ -454,47 +391,32 @@ impl<'a> From<Cow<'a, str>> for Box<dyn Error> {
} }
#[unstable(feature = "never_type", issue = "35121")] #[unstable(feature = "never_type", issue = "35121")]
impl Error for ! { impl Error for ! {}
fn description(&self) -> &str {
*self
}
}
#[unstable( #[unstable(
feature = "allocator_api", feature = "allocator_api",
reason = "the precise API and guarantees it provides may be tweaked.", reason = "the precise API and guarantees it provides may be tweaked.",
issue = "32838" issue = "32838"
)] )]
impl Error for AllocErr { impl Error for AllocErr {}
fn description(&self) -> &str {
"memory allocation failed"
}
}
#[unstable( #[unstable(
feature = "allocator_api", feature = "allocator_api",
reason = "the precise API and guarantees it provides may be tweaked.", reason = "the precise API and guarantees it provides may be tweaked.",
issue = "32838" issue = "32838"
)] )]
impl Error for LayoutErr { impl Error for LayoutErr {}
fn description(&self) -> &str {
"invalid parameters to Layout::from_size_align"
}
}
#[unstable( #[unstable(
feature = "allocator_api", feature = "allocator_api",
reason = "the precise API and guarantees it provides may be tweaked.", reason = "the precise API and guarantees it provides may be tweaked.",
issue = "32838" issue = "32838"
)] )]
impl Error for CannotReallocInPlace { impl Error for CannotReallocInPlace {}
fn description(&self) -> &str {
CannotReallocInPlace::description(self)
}
}
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Error for str::ParseBoolError { impl Error for str::ParseBoolError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"failed to parse bool" "failed to parse bool"
} }
@ -502,6 +424,7 @@ impl Error for str::ParseBoolError {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Error for str::Utf8Error { impl Error for str::Utf8Error {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"invalid utf-8: corrupt contents" "invalid utf-8: corrupt contents"
} }
@ -509,6 +432,7 @@ impl Error for str::Utf8Error {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Error for num::ParseIntError { impl Error for num::ParseIntError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
self.__description() self.__description()
} }
@ -516,6 +440,7 @@ impl Error for num::ParseIntError {
#[stable(feature = "try_from", since = "1.34.0")] #[stable(feature = "try_from", since = "1.34.0")]
impl Error for num::TryFromIntError { impl Error for num::TryFromIntError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
self.__description() self.__description()
} }
@ -523,6 +448,7 @@ impl Error for num::TryFromIntError {
#[stable(feature = "try_from", since = "1.34.0")] #[stable(feature = "try_from", since = "1.34.0")]
impl Error for array::TryFromSliceError { impl Error for array::TryFromSliceError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
self.__description() self.__description()
} }
@ -530,6 +456,7 @@ impl Error for array::TryFromSliceError {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Error for num::ParseFloatError { impl Error for num::ParseFloatError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
self.__description() self.__description()
} }
@ -537,6 +464,7 @@ impl Error for num::ParseFloatError {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Error for string::FromUtf8Error { impl Error for string::FromUtf8Error {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"invalid utf-8" "invalid utf-8"
} }
@ -544,6 +472,7 @@ impl Error for string::FromUtf8Error {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Error for string::FromUtf16Error { impl Error for string::FromUtf16Error {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"invalid utf-16" "invalid utf-16"
} }
@ -558,6 +487,7 @@ impl Error for string::ParseError {
#[stable(feature = "decode_utf16", since = "1.9.0")] #[stable(feature = "decode_utf16", since = "1.9.0")]
impl Error for char::DecodeUtf16Error { impl Error for char::DecodeUtf16Error {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"unpaired surrogate found" "unpaired surrogate found"
} }
@ -565,6 +495,7 @@ impl Error for char::DecodeUtf16Error {
#[stable(feature = "box_error", since = "1.8.0")] #[stable(feature = "box_error", since = "1.8.0")]
impl<T: Error> Error for Box<T> { impl<T: Error> Error for Box<T> {
#[allow(deprecated, deprecated_in_future)]
fn description(&self) -> &str { fn description(&self) -> &str {
Error::description(&**self) Error::description(&**self)
} }
@ -581,6 +512,7 @@ impl<T: Error> Error for Box<T> {
#[stable(feature = "fmt_error", since = "1.11.0")] #[stable(feature = "fmt_error", since = "1.11.0")]
impl Error for fmt::Error { impl Error for fmt::Error {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"an error occurred when formatting an argument" "an error occurred when formatting an argument"
} }
@ -588,6 +520,7 @@ impl Error for fmt::Error {
#[stable(feature = "try_borrow", since = "1.13.0")] #[stable(feature = "try_borrow", since = "1.13.0")]
impl Error for cell::BorrowError { impl Error for cell::BorrowError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"already mutably borrowed" "already mutably borrowed"
} }
@ -595,6 +528,7 @@ impl Error for cell::BorrowError {
#[stable(feature = "try_borrow", since = "1.13.0")] #[stable(feature = "try_borrow", since = "1.13.0")]
impl Error for cell::BorrowMutError { impl Error for cell::BorrowMutError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"already borrowed" "already borrowed"
} }
@ -602,6 +536,7 @@ impl Error for cell::BorrowMutError {
#[stable(feature = "try_from", since = "1.34.0")] #[stable(feature = "try_from", since = "1.34.0")]
impl Error for char::CharTryFromError { impl Error for char::CharTryFromError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"converted integer out of range for `char`" "converted integer out of range for `char`"
} }
@ -609,6 +544,7 @@ impl Error for char::CharTryFromError {
#[stable(feature = "char_from_str", since = "1.20.0")] #[stable(feature = "char_from_str", since = "1.20.0")]
impl Error for char::ParseCharError { impl Error for char::ParseCharError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
self.__description() self.__description()
} }
@ -846,16 +782,8 @@ mod tests {
} }
} }
impl Error for A { impl Error for A {}
fn description(&self) -> &str { impl Error for B {}
"A-desc"
}
}
impl Error for B {
fn description(&self) -> &str {
"A-desc"
}
}
#[test] #[test]
fn downcasting() { fn downcasting() {

View File

@ -878,6 +878,7 @@ impl NulError {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl Error for NulError { impl Error for NulError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"nul byte found in data" "nul byte found in data"
} }
@ -903,6 +904,7 @@ impl From<NulError> for io::Error {
#[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")] #[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")]
impl Error for FromBytesWithNulError { impl Error for FromBytesWithNulError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
match self.kind { match self.kind {
FromBytesWithNulErrorKind::InteriorNul(..) => { FromBytesWithNulErrorKind::InteriorNul(..) => {
@ -915,6 +917,7 @@ impl Error for FromBytesWithNulError {
#[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")] #[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")]
impl fmt::Display for FromBytesWithNulError { impl fmt::Display for FromBytesWithNulError {
#[allow(deprecated, deprecated_in_future)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.description())?; f.write_str(self.description())?;
if let FromBytesWithNulErrorKind::InteriorNul(pos) = self.kind { if let FromBytesWithNulErrorKind::InteriorNul(pos) = self.kind {
@ -943,6 +946,7 @@ impl IntoStringError {
#[stable(feature = "cstring_into", since = "1.7.0")] #[stable(feature = "cstring_into", since = "1.7.0")]
impl Error for IntoStringError { impl Error for IntoStringError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"C string contained non-utf8 bytes" "C string contained non-utf8 bytes"
} }
@ -954,6 +958,7 @@ impl Error for IntoStringError {
#[stable(feature = "cstring_into", since = "1.7.0")] #[stable(feature = "cstring_into", since = "1.7.0")]
impl fmt::Display for IntoStringError { impl fmt::Display for IntoStringError {
#[allow(deprecated, deprecated_in_future)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.description().fmt(f) self.description().fmt(f)
} }

View File

@ -752,6 +752,7 @@ impl<W> From<IntoInnerError<W>> for Error {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<W: Send + fmt::Debug> error::Error for IntoInnerError<W> { impl<W: Send + fmt::Debug> error::Error for IntoInnerError<W> {
#[allow(deprecated, deprecated_in_future)]
fn description(&self) -> &str { fn description(&self) -> &str {
error::Error::description(self.error()) error::Error::description(self.error())
} }

View File

@ -534,6 +534,7 @@ impl fmt::Display for Error {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl error::Error for Error { impl error::Error for Error {
#[allow(deprecated, deprecated_in_future)]
fn description(&self) -> &str { fn description(&self) -> &str {
match self.repr { match self.repr {
Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(), Repr::Os(..) | Repr::Simple(..) => self.kind().as_str(),
@ -603,22 +604,18 @@ mod test {
struct TestError; struct TestError;
impl fmt::Display for TestError { impl fmt::Display for TestError {
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Ok(()) f.write_str("asdf")
} }
} }
impl error::Error for TestError { impl error::Error for TestError {}
fn description(&self) -> &str {
"asdf"
}
}
// we have to call all of these UFCS style right now since method // we have to call all of these UFCS style right now since method
// resolution won't implicitly drop the Send+Sync bounds // resolution won't implicitly drop the Send+Sync bounds
let mut err = Error::new(ErrorKind::Other, TestError); let mut err = Error::new(ErrorKind::Other, TestError);
assert!(err.get_ref().unwrap().is::<TestError>()); assert!(err.get_ref().unwrap().is::<TestError>());
assert_eq!("asdf", err.get_ref().unwrap().description()); assert_eq!("asdf", err.get_ref().unwrap().to_string());
assert!(err.get_mut().unwrap().is::<TestError>()); assert!(err.get_mut().unwrap().is::<TestError>());
let extracted = err.into_inner().unwrap(); let extracted = err.into_inner().unwrap();
extracted.downcast::<TestError>().unwrap(); extracted.downcast::<TestError>().unwrap();

View File

@ -363,6 +363,7 @@ pub struct AddrParseError(());
#[stable(feature = "addr_parse_error_error", since = "1.4.0")] #[stable(feature = "addr_parse_error_error", since = "1.4.0")]
impl fmt::Display for AddrParseError { impl fmt::Display for AddrParseError {
#[allow(deprecated, deprecated_in_future)]
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.write_str(self.description()) fmt.write_str(self.description())
} }
@ -370,6 +371,7 @@ impl fmt::Display for AddrParseError {
#[stable(feature = "addr_parse_error_error", since = "1.4.0")] #[stable(feature = "addr_parse_error_error", since = "1.4.0")]
impl Error for AddrParseError { impl Error for AddrParseError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"invalid IP address syntax" "invalid IP address syntax"
} }

View File

@ -2786,6 +2786,7 @@ impl_cmp_os_str!(Cow<'a, Path>, OsString);
#[stable(since = "1.7.0", feature = "strip_prefix")] #[stable(since = "1.7.0", feature = "strip_prefix")]
impl fmt::Display for StripPrefixError { impl fmt::Display for StripPrefixError {
#[allow(deprecated, deprecated_in_future)]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.description().fmt(f) self.description().fmt(f)
} }
@ -2793,6 +2794,7 @@ impl fmt::Display for StripPrefixError {
#[stable(since = "1.7.0", feature = "strip_prefix")] #[stable(since = "1.7.0", feature = "strip_prefix")]
impl Error for StripPrefixError { impl Error for StripPrefixError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"prefix not found" "prefix not found"
} }

View File

@ -1550,6 +1550,7 @@ impl<T> fmt::Display for SendError<T> {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T: Send> error::Error for SendError<T> { impl<T: Send> error::Error for SendError<T> {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"sending on a closed channel" "sending on a closed channel"
} }
@ -1577,6 +1578,7 @@ impl<T> fmt::Display for TrySendError<T> {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T: Send> error::Error for TrySendError<T> { impl<T: Send> error::Error for TrySendError<T> {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
match *self { match *self {
TrySendError::Full(..) => "sending on a full channel", TrySendError::Full(..) => "sending on a full channel",
@ -1603,6 +1605,7 @@ impl fmt::Display for RecvError {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl error::Error for RecvError { impl error::Error for RecvError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"receiving on a closed channel" "receiving on a closed channel"
} }
@ -1620,6 +1623,7 @@ impl fmt::Display for TryRecvError {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl error::Error for TryRecvError { impl error::Error for TryRecvError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
match *self { match *self {
TryRecvError::Empty => "receiving on an empty channel", 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")] #[stable(feature = "mpsc_recv_timeout_error", since = "1.15.0")]
impl error::Error for RecvTimeoutError { impl error::Error for RecvTimeoutError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
match *self { match *self {
RecvTimeoutError::Timeout => "timed out waiting on channel", RecvTimeoutError::Timeout => "timed out waiting on channel",

View File

@ -63,6 +63,7 @@ impl fmt::Display for JoinPathsError {
} }
impl StdError for JoinPathsError { impl StdError for JoinPathsError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"not supported on CloudABI yet" "not supported on CloudABI yet"
} }

View File

@ -61,6 +61,7 @@ impl fmt::Display for JoinPathsError {
} }
impl StdError for JoinPathsError { impl StdError for JoinPathsError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"not supported on hermit yet" "not supported on hermit yet"
} }

View File

@ -440,6 +440,7 @@ pub struct NonIpSockAddr {
} }
impl error::Error for NonIpSockAddr { impl error::Error for NonIpSockAddr {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"Failed to convert address to SocketAddr" "Failed to convert address to SocketAddr"
} }

View File

@ -66,6 +66,7 @@ impl fmt::Display for JoinPathsError {
} }
impl StdError for JoinPathsError { impl StdError for JoinPathsError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"not supported in SGX yet" "not supported in SGX yet"
} }

View File

@ -213,6 +213,7 @@ impl fmt::Display for JoinPathsError {
} }
impl StdError for JoinPathsError { impl StdError for JoinPathsError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"failed to join paths" "failed to join paths"
} }

View File

@ -173,6 +173,7 @@ impl fmt::Display for JoinPathsError {
} }
impl StdError for JoinPathsError { impl StdError for JoinPathsError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"failed to join paths" "failed to join paths"
} }

View File

@ -78,6 +78,7 @@ impl fmt::Display for JoinPathsError {
} }
impl StdError for JoinPathsError { impl StdError for JoinPathsError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"not supported on wasm yet" "not supported on wasm yet"
} }

View File

@ -53,6 +53,7 @@ impl fmt::Display for JoinPathsError {
} }
impl StdError for JoinPathsError { impl StdError for JoinPathsError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"not supported on wasm yet" "not supported on wasm yet"
} }

View File

@ -225,6 +225,7 @@ impl fmt::Display for JoinPathsError {
} }
impl StdError for JoinPathsError { impl StdError for JoinPathsError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"failed to join paths" "failed to join paths"
} }

View File

@ -148,6 +148,7 @@ impl<T> fmt::Display for PoisonError<T> {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T> Error for PoisonError<T> { impl<T> Error for PoisonError<T> {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"poisoned lock: another task failed inside" "poisoned lock: another task failed inside"
} }
@ -239,6 +240,7 @@ impl<T> fmt::Display for TryLockError<T> {
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
impl<T> Error for TryLockError<T> { impl<T> Error for TryLockError<T> {
#[allow(deprecated, deprecated_in_future)]
fn description(&self) -> &str { fn description(&self) -> &str {
match *self { match *self {
TryLockError::Poisoned(ref p) => p.description(), TryLockError::Poisoned(ref p) => p.description(),
@ -246,6 +248,7 @@ impl<T> Error for TryLockError<T> {
} }
} }
#[allow(deprecated)]
fn cause(&self) -> Option<&dyn Error> { fn cause(&self) -> Option<&dyn Error> {
match *self { match *self {
TryLockError::Poisoned(ref p) => Some(p), TryLockError::Poisoned(ref p) => Some(p),

View File

@ -621,6 +621,7 @@ impl SystemTimeError {
#[stable(feature = "time2", since = "1.8.0")] #[stable(feature = "time2", since = "1.8.0")]
impl Error for SystemTimeError { impl Error for SystemTimeError {
#[allow(deprecated)]
fn description(&self) -> &str { fn description(&self) -> &str {
"other time was not earlier than self" "other time was not earlier than self"
} }

View File

@ -23,8 +23,4 @@ impl std::fmt::Display for FatalError {
} }
} }
impl std::error::Error for FatalError { impl std::error::Error for FatalError {}
fn description(&self) -> &str {
"The parser has encountered a fatal error"
}
}

View File

@ -42,14 +42,10 @@ pub enum Error {
} }
impl error::Error for Error { impl error::Error for Error {
fn description(&self) -> &str { fn source(&self) -> Option<&(dyn error::Error + 'static)> {
"failed to create TermInfo"
}
fn cause(&self) -> Option<&dyn error::Error> {
use Error::*; use Error::*;
match *self { match self {
IoError(ref e) => Some(e), IoError(e) => Some(e),
_ => None, _ => None,
} }
} }

View File

@ -10,7 +10,7 @@ error: internal compiler error: mutable allocation in constant
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _; LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:349:17 thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:345:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace. note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: internal compiler error: unexpected panic error: internal compiler error: unexpected panic

View File

@ -286,7 +286,7 @@ fn main() {
let (format, dst) = parse_args(); let (format, dst) = parse_args();
let result = syntax::with_default_globals(move || main_with_result(format, &dst)); let result = syntax::with_default_globals(move || main_with_result(format, &dst));
if let Err(e) = result { if let Err(e) = result {
panic!("{}", e.description()); panic!("{}", e.to_string());
} }
} }