diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-03-31 11:27:21 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-31 15:53:39 -0700 |
| commit | e10ee2c8572421c056ea68e6656fee936e0330d8 (patch) | |
| tree | b66a0ecb48f039e3789837fd45d83d4461fb1035 | |
| parent | da04788efca6ec1e421139fb4916a5aacd49a2e2 (diff) | |
| parent | e17f4fc1d4545f5c17b21805c5145b05495484ee (diff) | |
| download | rust-e10ee2c8572421c056ea68e6656fee936e0330d8.tar.gz rust-e10ee2c8572421c056ea68e6656fee936e0330d8.zip | |
rollup merge of #23879: seanmonstar/del-from-error
Conflicts: src/libcore/error.rs
| -rw-r--r-- | src/liballoc/boxed.rs | 6 | ||||
| -rw-r--r-- | src/libcore/convert.rs | 7 | ||||
| -rw-r--r-- | src/libcore/error.rs | 59 | ||||
| -rw-r--r-- | src/libcore/macros.rs | 2 | ||||
| -rw-r--r-- | src/libserialize/json.rs | 4 | ||||
| -rw-r--r-- | src/libstd/ffi/c_str.rs | 10 | ||||
| -rw-r--r-- | src/libstd/io/buffered.rs | 6 | ||||
| -rw-r--r-- | src/libstd/macros.rs | 2 | ||||
| -rw-r--r-- | src/libstd/os.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sync/poison.rs | 6 |
10 files changed, 26 insertions, 78 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 48dce3d8815..f3c0dd0c3dc 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -51,7 +51,7 @@ use core::prelude::*; use core::any::Any; use core::cmp::Ordering; use core::default::Default; -use core::error::{Error, FromError}; +use core::error::Error; use core::fmt; use core::hash::{self, Hash}; use core::mem; @@ -308,8 +308,8 @@ impl<I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for Box<I> { impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> {} #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, E: Error + 'a> FromError<E> for Box<Error + 'a> { - fn from_error(err: E) -> Box<Error + 'a> { +impl<'a, E: Error + 'a> From<E> for Box<Error + 'a> { + fn from(err: E) -> Box<Error + 'a> { Box::new(err) } } diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 4a99f1a756a..62ca8c47ab6 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -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> { diff --git a/src/libcore/error.rs b/src/libcore/error.rs index 9430aa00668..24035b7d9a8 100644 --- a/src/libcore/error.rs +++ b/src/libcore/error.rs @@ -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 - } -} 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) => ({ diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index c47568520a0..cdfe212bf23 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -367,8 +367,8 @@ impl std::error::Error for EncoderError { fn description(&self) -> &str { "encoder error" } } -impl std::error::FromError<fmt::Error> for EncoderError { - fn from_error(err: fmt::Error) -> EncoderError { EncoderError::FmtError(err) } +impl From<fmt::Error> for EncoderError { + fn from(err: fmt::Error) -> EncoderError { EncoderError::FmtError(err) } } pub type EncodeResult = Result<(), EncoderError>; diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index a00f7708025..f5c7d1d18d5 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -12,7 +12,7 @@ use convert::Into; use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering}; -use error::{Error, FromError}; +use error::Error; use fmt; use io; use iter::Iterator; @@ -298,8 +298,8 @@ impl fmt::Display for NulError { } #[stable(feature = "rust1", since = "1.0.0")] -impl FromError<NulError> for io::Error { - fn from_error(_: NulError) -> io::Error { +impl From<NulError> for io::Error { + fn from(_: NulError) -> io::Error { io::Error::new(io::ErrorKind::InvalidInput, "data provided contains a nul byte", None) } @@ -307,8 +307,8 @@ impl FromError<NulError> for io::Error { #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated)] -impl FromError<NulError> for old_io::IoError { - fn from_error(_: NulError) -> old_io::IoError { +impl From<NulError> for old_io::IoError { + fn from(_: NulError) -> old_io::IoError { old_io::IoError { kind: old_io::IoErrorKind::InvalidInput, desc: "data provided contains a nul byte", diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 8eea06bf6b0..628ad839c16 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -16,7 +16,7 @@ use prelude::v1::*; use io::prelude::*; use cmp; -use error::{self, FromError}; +use error; use fmt; use io::{self, DEFAULT_BUF_SIZE, Error, ErrorKind}; use ptr; @@ -264,8 +264,8 @@ impl<W> IntoInnerError<W> { } #[stable(feature = "rust1", since = "1.0.0")] -impl<W> FromError<IntoInnerError<W>> for Error { - fn from_error(iie: IntoInnerError<W>) -> Error { iie.1 } +impl<W> From<IntoInnerError<W>> for Error { + fn from(iie: IntoInnerError<W>) -> Error { iie.1 } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 645bc5db753..b3d1adb4421 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -101,7 +101,7 @@ macro_rules! try { ($expr:expr) => (match $expr { $crate::result::Result::Ok(val) => val, $crate::result::Result::Err(err) => { - return $crate::result::Result::Err($crate::error::FromError::from_error(err)) + return $crate::result::Result::Err($crate::convert::From::from(err)) } }) } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 2e3f47fea86..4ae3ad29c73 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -40,7 +40,7 @@ use boxed::Box; use clone::Clone; use convert::From; use env; -use error::{FromError, Error}; +use error::Error; use ffi::{OsString, OsStr}; use fmt; use iter::Iterator; diff --git a/src/libstd/sync/poison.rs b/src/libstd/sync/poison.rs index c07c83d37f4..cea2def30f1 100644 --- a/src/libstd/sync/poison.rs +++ b/src/libstd/sync/poison.rs @@ -11,7 +11,7 @@ use prelude::v1::*; use cell::UnsafeCell; -use error::{Error, FromError}; +use error::{Error}; use fmt; use thread; @@ -144,8 +144,8 @@ impl<T> PoisonError<T> { pub fn get_mut(&mut self) -> &mut T { &mut self.guard } } -impl<T> FromError<PoisonError<T>> for TryLockError<T> { - fn from_error(err: PoisonError<T>) -> TryLockError<T> { +impl<T> From<PoisonError<T>> for TryLockError<T> { + fn from(err: PoisonError<T>) -> TryLockError<T> { TryLockError::Poisoned(err) } } |
