Skip to content

Commit bcff76b

Browse files
committed
Auto merge of #66919 - dtolnay:description, r=<try>
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 4007d4e + b6194ab commit bcff76b

File tree

29 files changed

+113
-214
lines changed

29 files changed

+113
-214
lines changed

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 {}

src/librustc_error_codes/error_codes/E0638.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,23 @@ on it.
1212
```rust,ignore (pseudo-Rust)
1313
use std::error::Error as StdError;
1414
15-
#[non_exhaustive] pub enum Error {
16-
Message(String),
17-
Other,
15+
#[non_exhaustive]
16+
pub enum Error {
17+
Message(String),
18+
Other,
1819
}
1920
20-
impl StdError for Error {
21-
fn description(&self) -> &str {
21+
impl Display for Error {
22+
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
2223
// This will not error, despite being marked as non_exhaustive, as this
2324
// enum is defined within the current crate, it can be matched
2425
// exhaustively.
25-
match *self {
26-
Message(ref s) => s,
27-
Other => "other or unknown error",
28-
}
29-
}
26+
let display = match self {
27+
Message(s) => s,
28+
Other => "other or unknown error",
29+
};
30+
formatter.write_str(display)
31+
}
3032
}
3133
```
3234

@@ -38,9 +40,9 @@ use mycrate::Error;
3840
// This will not error as the non_exhaustive Error enum has been matched with a
3941
// wildcard.
4042
match error {
41-
Message(ref s) => ...,
42-
Other => ...,
43-
_ => ...,
43+
Message(s) => ...,
44+
Other => ...,
45+
_ => ...,
4446
}
4547
```
4648

src/librustc_errors/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,7 @@ impl fmt::Display for ExplicitBug {
251251
}
252252
}
253253

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

260256
pub use diagnostic::{Diagnostic, SubDiagnostic, DiagnosticStyledString, DiagnosticId};
261257
pub use diagnostic_builder::DiagnosticBuilder;

src/librustc_mir/const_eval.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,7 @@ impl fmt::Display for ConstEvalError {
200200
}
201201
}
202202

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

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

src/librustdoc/html/render.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,7 @@ pub struct Error {
100100
pub error: io::Error,
101101
}
102102

103-
impl error::Error for Error {
104-
fn description(&self) -> &str {
105-
self.error.description()
106-
}
107-
}
103+
impl error::Error for Error {}
108104

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

src/libserialize/hex.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,7 @@ impl fmt::Display for FromHexError {
6969
}
7070
}
7171

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

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

src/libserialize/json.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,7 @@ impl fmt::Display for DecoderError {
338338
}
339339
}
340340

341-
impl std::error::Error for DecoderError {
342-
fn description(&self) -> &str { "decoder error" }
343-
}
341+
impl std::error::Error for DecoderError {}
344342

345343
impl fmt::Display for EncoderError {
346344
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -349,9 +347,7 @@ impl fmt::Display for EncoderError {
349347
}
350348
}
351349

352-
impl std::error::Error for EncoderError {
353-
fn description(&self) -> &str { "encoder error" }
354-
}
350+
impl std::error::Error for EncoderError {}
355351

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

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)