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

Stabilize the Error trait #23541

Merged
merged 1 commit into from
Mar 24, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/libcore/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,21 @@
#![stable(feature = "rust1", since = "1.0.0")]

use prelude::*;
use fmt::Display;
use fmt::{Debug, Display};

/// Base functionality for all errors in Rust.
#[unstable(feature = "core",
reason = "the exact API of this trait may change")]
pub trait Error: Display {
/// A short description of the error; usually a static string.
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Error: Debug + Display + Send {
/// A short description of the error.
///
/// The description should not contain newlines or sentence-ending
/// punctuation, to facilitate embedding in larger user-facing
/// strings.
#[stable(feature = "rust1", since = "1.0.0")]
fn description(&self) -> &str;

/// The lower-level cause of this error, if any.
#[stable(feature = "rust1", since = "1.0.0")]
fn cause(&self) -> Option<&Error> { None }
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl<W> FromError<IntoInnerError<W>> for Error {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<W> error::Error for IntoInnerError<W> {
impl<W: Send + fmt::Debug> error::Error for IntoInnerError<W> {
fn description(&self) -> &str {
error::Error::description(self.error())
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ impl<T> fmt::Display for SendError<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> error::Error for SendError<T> {
impl<T: Send> error::Error for SendError<T> {

fn description(&self) -> &str {
"sending on a closed channel"
Expand Down Expand Up @@ -1013,7 +1013,7 @@ impl<T> fmt::Display for TrySendError<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> error::Error for TrySendError<T> {
impl<T: Send> error::Error for TrySendError<T> {

fn description(&self) -> &str {
match *self {
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/sync/poison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ impl<T> fmt::Debug for PoisonError<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> fmt::Display for PoisonError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.description().fmt(f)
"poisoned lock: another task failed inside".fmt(f)
Copy link
Member

Choose a reason for hiding this comment

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

How come this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

To avoid the Send bound on T. (since you're just going to get this text anyway...)

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right!

}
}

impl<T> Error for PoisonError<T> {
impl<T: Send> Error for PoisonError<T> {
fn description(&self) -> &str {
"poisoned lock: another task failed inside"
}
Expand Down Expand Up @@ -161,13 +161,13 @@ impl<T> fmt::Debug for TryLockError<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> fmt::Display for TryLockError<T> {
impl<T: Send> fmt::Display for TryLockError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.description().fmt(f)
}
}

impl<T> Error for TryLockError<T> {
impl<T: Send> Error for TryLockError<T> {
fn description(&self) -> &str {
match *self {
TryLockError::Poisoned(ref p) => p.description(),
Expand Down
1 change: 1 addition & 0 deletions src/rustbook/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub type CommandError = Box<Error + 'static>;
pub type CommandResult<T> = Result<T, CommandError>;

pub fn err(s: &str) -> CliError {
#[derive(Debug)]
struct E(String);

impl Error for E {
Expand Down