Skip to content

Commit e10ee2c

Browse files
committed
rollup merge of rust-lang#23879: seanmonstar/del-from-error
Conflicts: src/libcore/error.rs
2 parents da04788 + e17f4fc commit e10ee2c

File tree

10 files changed

+26
-78
lines changed

10 files changed

+26
-78
lines changed

src/liballoc/boxed.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use core::prelude::*;
5151
use core::any::Any;
5252
use core::cmp::Ordering;
5353
use core::default::Default;
54-
use core::error::{Error, FromError};
54+
use core::error::Error;
5555
use core::fmt;
5656
use core::hash::{self, Hash};
5757
use core::mem;
@@ -308,8 +308,8 @@ impl<I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for Box<I> {
308308
impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> {}
309309

310310
#[stable(feature = "rust1", since = "1.0.0")]
311-
impl<'a, E: Error + 'a> FromError<E> for Box<Error + 'a> {
312-
fn from_error(err: E) -> Box<Error + 'a> {
311+
impl<'a, E: Error + 'a> From<E> for Box<Error + 'a> {
312+
fn from(err: E) -> Box<Error + 'a> {
313313
Box::new(err)
314314
}
315315
}

src/libcore/convert.rs

+7
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ impl<'a, T: ?Sized, U: ?Sized> AsMut<U> for &'a mut T where T: AsMut<U> {
9595
// }
9696
// }
9797

98+
// From itself is always itself
99+
impl<T> From<T> for T {
100+
fn from(t: T) -> T {
101+
t
102+
}
103+
}
104+
98105
// From implies Into
99106
#[stable(feature = "rust1", since = "1.0.0")]
100107
impl<T, U> Into<U> for T where U: From<T> {

src/libcore/error.rs

-59
Original file line numberDiff line numberDiff line change
@@ -33,49 +33,6 @@
3333
//! high-level module to provide its own errors that do not commit to any
3434
//! particular implementation, but also reveal some of its implementation for
3535
//! debugging via `cause` chains.
36-
//!
37-
//! # The `FromError` trait
38-
//!
39-
//! `FromError` is a simple trait that expresses conversions between different
40-
//! error types. To provide maximum flexibility, it does not require either of
41-
//! the types to actually implement the `Error` trait, although this will be the
42-
//! common case.
43-
//!
44-
//! The main use of this trait is in the `try!` macro, which uses it to
45-
//! automatically convert a given error to the error specified in a function's
46-
//! return type.
47-
//!
48-
//! For example,
49-
//!
50-
//! ```
51-
//! #![feature(core)]
52-
//! use std::error::FromError;
53-
//! use std::{io, str};
54-
//! use std::fs::File;
55-
//!
56-
//! enum MyError {
57-
//! Io(io::Error),
58-
//! Utf8(str::Utf8Error),
59-
//! }
60-
//!
61-
//! impl FromError<io::Error> for MyError {
62-
//! fn from_error(err: io::Error) -> MyError { MyError::Io(err) }
63-
//! }
64-
//!
65-
//! impl FromError<str::Utf8Error> for MyError {
66-
//! fn from_error(err: str::Utf8Error) -> MyError { MyError::Utf8(err) }
67-
//! }
68-
//!
69-
//! #[allow(unused_variables)]
70-
//! fn open_and_map() -> Result<(), MyError> {
71-
//! let b = b"foo.txt";
72-
//! let s = try!(str::from_utf8(b));
73-
//! let f = try!(File::open(s));
74-
//!
75-
//! // do something interesting here...
76-
//! Ok(())
77-
//! }
78-
//! ```
7936
8037
#![stable(feature = "rust1", since = "1.0.0")]
8138

@@ -97,19 +54,3 @@ pub trait Error: Debug + Display {
9754
#[stable(feature = "rust1", since = "1.0.0")]
9855
fn cause(&self) -> Option<&Error> { None }
9956
}
100-
101-
/// A trait for types that can be converted from a given error type `E`.
102-
#[stable(feature = "rust1", since = "1.0.0")]
103-
pub trait FromError<E> {
104-
/// Perform the conversion.
105-
#[stable(feature = "rust1", since = "1.0.0")]
106-
fn from_error(err: E) -> Self;
107-
}
108-
109-
// Any type is convertable from itself
110-
#[stable(feature = "rust1", since = "1.0.0")]
111-
impl<E> FromError<E> for E {
112-
fn from_error(err: E) -> E {
113-
err
114-
}
115-
}

src/libcore/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ macro_rules! debug_assert_eq {
156156

157157
/// Short circuiting evaluation on Err
158158
///
159-
/// `libstd` contains a more general `try!` macro that uses `FromError`.
159+
/// `libstd` contains a more general `try!` macro that uses `From<E>`.
160160
#[macro_export]
161161
macro_rules! try {
162162
($e:expr) => ({

src/libserialize/json.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ impl std::error::Error for EncoderError {
367367
fn description(&self) -> &str { "encoder error" }
368368
}
369369

370-
impl std::error::FromError<fmt::Error> for EncoderError {
371-
fn from_error(err: fmt::Error) -> EncoderError { EncoderError::FmtError(err) }
370+
impl From<fmt::Error> for EncoderError {
371+
fn from(err: fmt::Error) -> EncoderError { EncoderError::FmtError(err) }
372372
}
373373

374374
pub type EncodeResult = Result<(), EncoderError>;

src/libstd/ffi/c_str.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
use convert::Into;
1414
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
15-
use error::{Error, FromError};
15+
use error::Error;
1616
use fmt;
1717
use io;
1818
use iter::Iterator;
@@ -298,17 +298,17 @@ impl fmt::Display for NulError {
298298
}
299299

300300
#[stable(feature = "rust1", since = "1.0.0")]
301-
impl FromError<NulError> for io::Error {
302-
fn from_error(_: NulError) -> io::Error {
301+
impl From<NulError> for io::Error {
302+
fn from(_: NulError) -> io::Error {
303303
io::Error::new(io::ErrorKind::InvalidInput,
304304
"data provided contains a nul byte", None)
305305
}
306306
}
307307

308308
#[stable(feature = "rust1", since = "1.0.0")]
309309
#[allow(deprecated)]
310-
impl FromError<NulError> for old_io::IoError {
311-
fn from_error(_: NulError) -> old_io::IoError {
310+
impl From<NulError> for old_io::IoError {
311+
fn from(_: NulError) -> old_io::IoError {
312312
old_io::IoError {
313313
kind: old_io::IoErrorKind::InvalidInput,
314314
desc: "data provided contains a nul byte",

src/libstd/io/buffered.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use prelude::v1::*;
1616
use io::prelude::*;
1717

1818
use cmp;
19-
use error::{self, FromError};
19+
use error;
2020
use fmt;
2121
use io::{self, DEFAULT_BUF_SIZE, Error, ErrorKind};
2222
use ptr;
@@ -264,8 +264,8 @@ impl<W> IntoInnerError<W> {
264264
}
265265

266266
#[stable(feature = "rust1", since = "1.0.0")]
267-
impl<W> FromError<IntoInnerError<W>> for Error {
268-
fn from_error(iie: IntoInnerError<W>) -> Error { iie.1 }
267+
impl<W> From<IntoInnerError<W>> for Error {
268+
fn from(iie: IntoInnerError<W>) -> Error { iie.1 }
269269
}
270270

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

src/libstd/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ macro_rules! try {
101101
($expr:expr) => (match $expr {
102102
$crate::result::Result::Ok(val) => val,
103103
$crate::result::Result::Err(err) => {
104-
return $crate::result::Result::Err($crate::error::FromError::from_error(err))
104+
return $crate::result::Result::Err($crate::convert::From::from(err))
105105
}
106106
})
107107
}

src/libstd/os.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use boxed::Box;
4040
use clone::Clone;
4141
use convert::From;
4242
use env;
43-
use error::{FromError, Error};
43+
use error::Error;
4444
use ffi::{OsString, OsStr};
4545
use fmt;
4646
use iter::Iterator;

src/libstd/sync/poison.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use prelude::v1::*;
1212

1313
use cell::UnsafeCell;
14-
use error::{Error, FromError};
14+
use error::{Error};
1515
use fmt;
1616
use thread;
1717

@@ -144,8 +144,8 @@ impl<T> PoisonError<T> {
144144
pub fn get_mut(&mut self) -> &mut T { &mut self.guard }
145145
}
146146

147-
impl<T> FromError<PoisonError<T>> for TryLockError<T> {
148-
fn from_error(err: PoisonError<T>) -> TryLockError<T> {
147+
impl<T> From<PoisonError<T>> for TryLockError<T> {
148+
fn from(err: PoisonError<T>) -> TryLockError<T> {
149149
TryLockError::Poisoned(err)
150150
}
151151
}

0 commit comments

Comments
 (0)