rollup merge of #23879: seanmonstar/del-from-error
Conflicts: src/libcore/error.rs
This commit is contained in:
@@ -95,6 +95,13 @@ impl<'a, T: ?Sized, U: ?Sized> AsMut<U> for &'a mut T where T: AsMut<U> {
|
||||
// }
|
||||
// }
|
||||
|
||||
// From itself is always itself
|
||||
impl<T> From<T> for T {
|
||||
fn from(t: T) -> T {
|
||||
t
|
||||
}
|
||||
}
|
||||
|
||||
// From implies Into
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T, U> Into<U> for T where U: From<T> {
|
||||
|
||||
@@ -33,49 +33,6 @@
|
||||
//! 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.
|
||||
//!
|
||||
//! # The `FromError` trait
|
||||
//!
|
||||
//! `FromError` is a simple trait that expresses conversions between different
|
||||
//! error types. To provide maximum flexibility, it does not require either of
|
||||
//! the types to actually implement the `Error` trait, although this will be the
|
||||
//! common case.
|
||||
//!
|
||||
//! The main use of this trait is in the `try!` macro, which uses it to
|
||||
//! automatically convert a given error to the error specified in a function's
|
||||
//! return type.
|
||||
//!
|
||||
//! For example,
|
||||
//!
|
||||
//! ```
|
||||
//! #![feature(core)]
|
||||
//! use std::error::FromError;
|
||||
//! use std::{io, str};
|
||||
//! use std::fs::File;
|
||||
//!
|
||||
//! enum MyError {
|
||||
//! Io(io::Error),
|
||||
//! Utf8(str::Utf8Error),
|
||||
//! }
|
||||
//!
|
||||
//! impl FromError<io::Error> for MyError {
|
||||
//! fn from_error(err: io::Error) -> MyError { MyError::Io(err) }
|
||||
//! }
|
||||
//!
|
||||
//! impl FromError<str::Utf8Error> for MyError {
|
||||
//! fn from_error(err: str::Utf8Error) -> MyError { MyError::Utf8(err) }
|
||||
//! }
|
||||
//!
|
||||
//! #[allow(unused_variables)]
|
||||
//! fn open_and_map() -> Result<(), MyError> {
|
||||
//! let b = b"foo.txt";
|
||||
//! let s = try!(str::from_utf8(b));
|
||||
//! let f = try!(File::open(s));
|
||||
//!
|
||||
//! // do something interesting here...
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
@@ -97,19 +54,3 @@ pub trait Error: Debug + Display {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn cause(&self) -> Option<&Error> { None }
|
||||
}
|
||||
|
||||
/// A trait for types that can be converted from a given error type `E`.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub trait FromError<E> {
|
||||
/// Perform the conversion.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn from_error(err: E) -> Self;
|
||||
}
|
||||
|
||||
// Any type is convertable from itself
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<E> FromError<E> for E {
|
||||
fn from_error(err: E) -> E {
|
||||
err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ macro_rules! debug_assert_eq {
|
||||
|
||||
/// Short circuiting evaluation on Err
|
||||
///
|
||||
/// `libstd` contains a more general `try!` macro that uses `FromError`.
|
||||
/// `libstd` contains a more general `try!` macro that uses `From<E>`.
|
||||
#[macro_export]
|
||||
macro_rules! try {
|
||||
($e:expr) => ({
|
||||
|
||||
Reference in New Issue
Block a user