Skip to content

Commit 03f46ad

Browse files
committed
Add a default impl for Error::description and document it as deprecated.
It is redundant with Display while being much less flexible for implementors. This is only a "soft" deprecation: it is not worth the hassle of a warning to existing users.
1 parent 0b5cc19 commit 03f46ad

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/libstd/error.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,29 @@ use string;
5252
/// [`cause`]: trait.Error.html#method.cause
5353
#[stable(feature = "rust1", since = "1.0.0")]
5454
pub trait Error: Debug + Display {
55-
/// A short description of the error.
55+
/// **This method is soft-deprecated.**
5656
///
57-
/// The description should only be used for a simple message.
58-
/// It should not contain newlines or sentence-ending punctuation,
59-
/// to facilitate embedding in larger user-facing strings.
60-
/// For showing formatted error messages with more information see
61-
/// [`Display`].
57+
/// Although using it won’t cause compilation warning,
58+
/// new code should use [`Display`] instead
59+
/// and new `impl`s can omit it.
6260
///
6361
/// [`Display`]: ../fmt/trait.Display.html
6462
///
6563
/// # Examples
6664
///
6765
/// ```
68-
/// use std::error::Error;
69-
///
7066
/// match "xc".parse::<u32>() {
7167
/// Err(e) => {
72-
/// println!("Error: {}", e.description());
68+
/// // Print `e` itself, not `e.description()`.
69+
/// println!("Error: {}", e);
7370
/// }
7471
/// _ => println!("No error"),
7572
/// }
7673
/// ```
7774
#[stable(feature = "rust1", since = "1.0.0")]
78-
fn description(&self) -> &str;
75+
fn description(&self) -> &str {
76+
""
77+
}
7978

8079
/// The lower-level cause of this error, if any.
8180
///

0 commit comments

Comments
 (0)