Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Error::description for real #66919

Merged
merged 1 commit into from
Dec 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/librustc_driver/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>, Error> {
if arg.starts_with("@") {
Expand Down Expand Up @@ -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 {}
30 changes: 15 additions & 15 deletions src/librustc_error_codes/error_codes/E0638.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ For example, in the below example, since the enum is marked as
on it.

```rust,ignore (pseudo-Rust)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still 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)
}
}
```

Expand All @@ -38,9 +38,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 => ...,
_ => ...,
}
```

Expand Down
6 changes: 1 addition & 5 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,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, DiagnosticId, DiagnosticStyledString, SubDiagnostic};
pub use diagnostic_builder::DiagnosticBuilder;
Expand Down
14 changes: 1 addition & 13 deletions src/librustc_mir/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,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",
ConstAccessesStatic => "constant accesses static",
}
}

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> {
Expand Down
6 changes: 1 addition & 5 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,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 {
Expand Down
9 changes: 1 addition & 8 deletions src/libserialize/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,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 `~`)
Expand Down
12 changes: 2 additions & 10 deletions src/libserialize/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,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 {
Expand All @@ -358,11 +354,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<fmt::Error> for EncoderError {
/// Converts a [`fmt::Error`] into `EncoderError`
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()
}
Expand Down
Loading