Skip to content

Commit

Permalink
Auto merge of #50163 - kornelski:error, r=Kimundi
Browse files Browse the repository at this point in the history
Bury Error::description()

Second attempt of #49536 rust-lang/rfcs#2230

The exact wording of the default implementation is still up in the air, but I think it's a detail that can be amended later.
  • Loading branch information
bors committed Apr 30, 2018
2 parents 64e6dda + 1912f39 commit 4745092
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/doc/book
Submodule book updated 222 files
65 changes: 26 additions & 39 deletions src/libstd/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,6 @@
// except according to those terms.

//! Traits for working with Errors.
//!
//! # The `Error` trait
//!
//! `Error` is a trait representing the basic expectations for error values,
//! i.e. values of type `E` in [`Result<T, E>`]. At a minimum, errors must provide
//! a description, but they may optionally provide additional detail (via
//! [`Display`]) and cause chain information:
//!
//! ```
//! use std::fmt::Display;
//!
//! trait Error: Display {
//! fn description(&self) -> &str;
//!
//! fn cause(&self) -> Option<&Error> { None }
//! }
//! ```
//!
//! The [`cause`] method is generally used when errors cross "abstraction
//! boundaries", i.e. when a one module must report an error that is "caused"
//! by an error from a lower-level module. This setup makes it possible for the
//! high-level module to provide its own errors that do not commit to any
//! particular implementation, but also reveal some of its implementation for
//! debugging via [`cause`] chains.
//!
//! [`Result<T, E>`]: ../result/enum.Result.html
//! [`Display`]: ../fmt/trait.Display.html
//! [`cause`]: trait.Error.html#method.cause

#![stable(feature = "rust1", since = "1.0.0")]

Expand All @@ -63,33 +35,48 @@ use num;
use str;
use string;

/// Base functionality for all errors in Rust.
/// `Error` is a trait representing the basic expectations for error values,
/// i.e. values of type `E` in [`Result<T, E>`]. Errors must describe
/// themselves through the [`Display`] and [`Debug`] traits, and may provide
/// cause chain information:
///
/// The [`cause`] method is generally used when errors cross "abstraction
/// boundaries", i.e. when a one module must report an error that is "caused"
/// by an error from a lower-level module. This setup makes it possible for the
/// high-level module to provide its own errors that do not commit to any
/// particular implementation, but also reveal some of its implementation for
/// debugging via [`cause`] chains.
///
/// [`Result<T, E>`]: ../result/enum.Result.html
/// [`Display`]: ../fmt/trait.Display.html
/// [`cause`]: trait.Error.html#method.cause
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Error: Debug + Display {
/// A short description of the error.
/// **This method is soft-deprecated.**
///
/// The description should only be used for a simple message.
/// It should not contain newlines or sentence-ending punctuation,
/// to facilitate embedding in larger user-facing strings.
/// For showing formatted error messages with more information see
/// [`Display`].
/// Although using it won’t cause compilation warning,
/// new code should use [`Display`] instead
/// and new `impl`s can omit it.
///
/// To obtain error description as a string, use `to_string()`.
///
/// [`Display`]: ../fmt/trait.Display.html
///
/// # Examples
///
/// ```
/// use std::error::Error;
///
/// match "xc".parse::<u32>() {
/// Err(e) => {
/// println!("Error: {}", e.description());
/// // Print `e` itself, not `e.description()`.
/// println!("Error: {}", e);
/// }
/// _ => println!("No error"),
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn description(&self) -> &str;
fn description(&self) -> &str {
"description() is deprecated; use Display"
}

/// The lower-level cause of this error, if any.
///
Expand Down

0 comments on commit 4745092

Please sign in to comment.