summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorSean McArthur <sean.monstar@gmail.com>2015-03-30 17:56:48 -0700
committerSean McArthur <sean.monstar@gmail.com>2015-03-30 18:08:58 -0700
commite17f4fc1d4545f5c17b21805c5145b05495484ee (patch)
tree73738e0f820177de7d6052ad15e01c868d7a24ae /src/libcore
parent9de34a84bb300bab1bf0227f577331620cd60511 (diff)
downloadrust-e17f4fc1d4545f5c17b21805c5145b05495484ee.tar.gz
rust-e17f4fc1d4545f5c17b21805c5145b05495484ee.zip
convert: remove FromError, use From<E> instead
This removes the FromError trait, since it can now be expressed using
the new convert::Into trait. All implementations of FromError<E> where
changed to From<E>, and `try!` was changed to use From::from instead.

Because this removes FromError, it is a breaking change, but fixing it
simply requires changing the words `FromError` to `From`, and
`from_error` to `from`.

[breaking-change]
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/convert.rs7
-rw-r--r--src/libcore/error.rs35
-rw-r--r--src/libcore/macros.rs2
3 files changed, 12 insertions, 32 deletions
diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs
index 21f9b1f5513..3680daa2d5e 100644
--- a/src/libcore/convert.rs
+++ b/src/libcore/convert.rs
@@ -99,6 +99,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
 impl<T, U> Into<U> for T where U: From<T> {
     fn into(self) -> U {
diff --git a/src/libcore/error.rs b/src/libcore/error.rs
index 51f3369a75b..73ec19f1a14 100644
--- a/src/libcore/error.rs
+++ b/src/libcore/error.rs
@@ -34,17 +34,6 @@
 //! 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,
 //!
 //! ```
@@ -59,14 +48,14 @@
 //!     Map(MapError)
 //! }
 //!
-//! impl FromError<IoError> for MyError {
-//!     fn from_error(err: IoError) -> MyError {
+//! impl From<IoError> for MyError {
+//!     fn from(err: IoError) -> MyError {
 //!         MyError::Io(err)
 //!     }
 //! }
 //!
-//! impl FromError<MapError> for MyError {
-//!     fn from_error(err: MapError) -> MyError {
+//! impl From<MapError> for MyError {
+//!     fn from(err: MapError) -> MyError {
 //!         MyError::Map(err)
 //!     }
 //! }
@@ -100,19 +89,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
-    }
-}
diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs
index d5a7c1d6b26..19626aa5056 100644
--- a/src/libcore/macros.rs
+++ b/src/libcore/macros.rs
@@ -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) => ({