Skip to content

Commit bbf1372

Browse files
committed
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)
2 parents ed33453 + 4646a88 commit bbf1372

File tree

30 files changed

+107
-200
lines changed

30 files changed

+107
-200
lines changed

Diff for: src/librustc_driver/args.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::error;
22
use std::fmt;
33
use std::fs;
44
use std::io;
5-
use std::str;
65

76
pub fn arg_expand(arg: String) -> Result<Vec<String>, Error> {
87
if arg.starts_with("@") {
@@ -36,8 +35,4 @@ impl fmt::Display for Error {
3635
}
3736
}
3837

39-
impl error::Error for Error {
40-
fn description(&self) -> &'static str {
41-
"argument error"
42-
}
43-
}
38+
impl error::Error for Error {}

Diff for: src/librustc_error_codes/error_codes/E0638.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ For example, in the below example, since the enum is marked as
1010
on it.
1111

1212
```rust,ignore (pseudo-Rust)
13-
use std::error::Error as StdError;
14-
15-
#[non_exhaustive] pub enum Error {
16-
Message(String),
17-
Other,
13+
#[non_exhaustive]
14+
pub enum Error {
15+
Message(String),
16+
Other,
1817
}
1918
20-
impl StdError for Error {
21-
fn description(&self) -> &str {
19+
impl Display for Error {
20+
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
2221
// This will not error, despite being marked as non_exhaustive, as this
2322
// enum is defined within the current crate, it can be matched
2423
// exhaustively.
25-
match *self {
26-
Message(ref s) => s,
27-
Other => "other or unknown error",
28-
}
29-
}
24+
let display = match self {
25+
Message(s) => s,
26+
Other => "other or unknown error",
27+
};
28+
formatter.write_str(display)
29+
}
3030
}
3131
```
3232

@@ -38,9 +38,9 @@ use mycrate::Error;
3838
// This will not error as the non_exhaustive Error enum has been matched with a
3939
// wildcard.
4040
match error {
41-
Message(ref s) => ...,
42-
Other => ...,
43-
_ => ...,
41+
Message(s) => ...,
42+
Other => ...,
43+
_ => ...,
4444
}
4545
```
4646

Diff for: src/librustc_errors/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,7 @@ impl fmt::Display for ExplicitBug {
253253
}
254254
}
255255

256-
impl error::Error for ExplicitBug {
257-
fn description(&self) -> &str {
258-
"The parser has encountered an internal bug"
259-
}
260-
}
256+
impl error::Error for ExplicitBug {}
261257

262258
pub use diagnostic::{Diagnostic, DiagnosticId, DiagnosticStyledString, SubDiagnostic};
263259
pub use diagnostic_builder::DiagnosticBuilder;

Diff for: src/librustc_mir/const_eval.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,7 @@ impl fmt::Display for ConstEvalError {
197197
}
198198
}
199199

200-
impl Error for ConstEvalError {
201-
fn description(&self) -> &str {
202-
use self::ConstEvalError::*;
203-
match *self {
204-
NeedsRfc(_) => "this feature needs an rfc before being allowed inside constants",
205-
ConstAccessesStatic => "constant accesses static",
206-
}
207-
}
208-
209-
fn cause(&self) -> Option<&dyn Error> {
210-
None
211-
}
212-
}
200+
impl Error for ConstEvalError {}
213201

214202
// Extra machine state for CTFE, and the Machine instance
215203
pub struct CompileTimeInterpreter<'mir, 'tcx> {

Diff for: src/librustdoc/html/render.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,7 @@ pub struct Error {
9898
pub error: io::Error,
9999
}
100100

101-
impl error::Error for Error {
102-
fn description(&self) -> &str {
103-
self.error.description()
104-
}
105-
}
101+
impl error::Error for Error {}
106102

107103
impl std::fmt::Display for Error {
108104
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {

Diff for: src/libserialize/hex.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,7 @@ impl fmt::Display for FromHexError {
6868
}
6969
}
7070

71-
impl error::Error for FromHexError {
72-
fn description(&self) -> &str {
73-
match *self {
74-
InvalidHexCharacter(..) => "invalid character",
75-
InvalidHexLength => "invalid length",
76-
}
77-
}
78-
}
71+
impl error::Error for FromHexError {}
7972

8073
impl FromHex for str {
8174
/// Converts any hexadecimal encoded string (literal, `@`, `&`, or `~`)

Diff for: src/libserialize/json.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,7 @@ impl fmt::Display for DecoderError {
345345
}
346346
}
347347

348-
impl std::error::Error for DecoderError {
349-
fn description(&self) -> &str {
350-
"decoder error"
351-
}
352-
}
348+
impl std::error::Error for DecoderError {}
353349

354350
impl fmt::Display for EncoderError {
355351
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -358,11 +354,7 @@ impl fmt::Display for EncoderError {
358354
}
359355
}
360356

361-
impl std::error::Error for EncoderError {
362-
fn description(&self) -> &str {
363-
"encoder error"
364-
}
365-
}
357+
impl std::error::Error for EncoderError {}
366358

367359
impl From<fmt::Error> for EncoderError {
368360
/// Converts a [`fmt::Error`] into `EncoderError`

Diff for: src/libstd/env.rs

+2
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ impl fmt::Display for VarError {
284284

285285
#[stable(feature = "env", since = "1.0.0")]
286286
impl Error for VarError {
287+
#[allow(deprecated)]
287288
fn description(&self) -> &str {
288289
match *self {
289290
VarError::NotPresent => "environment variable not found",
@@ -526,6 +527,7 @@ impl fmt::Display for JoinPathsError {
526527

527528
#[stable(feature = "env", since = "1.0.0")]
528529
impl Error for JoinPathsError {
530+
#[allow(deprecated, deprecated_in_future)]
529531
fn description(&self) -> &str {
530532
self.inner.description()
531533
}

0 commit comments

Comments
 (0)