about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/ffi/c_str.rs2
-rw-r--r--src/libstd/fs.rs3
-rw-r--r--src/libstd/io/buffered.rs2
-rw-r--r--src/libstd/io/cursor.rs3
-rw-r--r--src/libstd/io/error.rs67
-rw-r--r--src/libstd/io/impls.rs2
-rw-r--r--src/libstd/io/mod.rs7
-rw-r--r--src/libstd/net/addr.rs2
-rw-r--r--src/libstd/net/mod.rs2
-rw-r--r--src/libstd/net/udp.rs2
-rw-r--r--src/libstd/process.rs1
-rw-r--r--src/libstd/sys/common/net2.rs5
-rw-r--r--src/libstd/sys/unix/net.rs3
13 files changed, 49 insertions, 52 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs
index 42ea50bff77..de91e5f3268 100644
--- a/src/libstd/ffi/c_str.rs
+++ b/src/libstd/ffi/c_str.rs
@@ -241,7 +241,7 @@ impl fmt::Display for NulError {
 impl From<NulError> for io::Error {
     fn from(_: NulError) -> io::Error {
         io::Error::new(io::ErrorKind::InvalidInput,
-                       "data provided contains a nul byte", None)
+                       "data provided contains a nul byte")
     }
 }
 
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index c34d128081b..4f97ae8f69b 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -576,8 +576,7 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
     let to = to.as_ref();
     if !from.is_file() {
         return Err(Error::new(ErrorKind::InvalidInput,
-                              "the source path is not an existing file",
-                              None))
+                              "the source path is not an existing file"))
     }
 
     let mut reader = try!(File::open(from));
diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs
index 628ad839c16..479665c4728 100644
--- a/src/libstd/io/buffered.rs
+++ b/src/libstd/io/buffered.rs
@@ -165,7 +165,7 @@ impl<W: Write> BufWriter<W> {
             match self.inner.as_mut().unwrap().write(&self.buf[written..]) {
                 Ok(0) => {
                     ret = Err(Error::new(ErrorKind::WriteZero,
-                                         "failed to write the buffered data", None));
+                                         "failed to write the buffered data"));
                     break;
                 }
                 Ok(n) => written += n,
diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs
index ad81143b7b4..a7b7f96c22b 100644
--- a/src/libstd/io/cursor.rs
+++ b/src/libstd/io/cursor.rs
@@ -75,8 +75,7 @@ macro_rules! seek {
 
             if pos < 0 {
                 Err(Error::new(ErrorKind::InvalidInput,
-                               "invalid seek to a negative position",
-                               None))
+                               "invalid seek to a negative position"))
             } else {
                 self.pos = pos as u64;
                 Ok(self.pos)
diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs
index 615df771e9b..b84dcb8fb62 100644
--- a/src/libstd/io/error.rs
+++ b/src/libstd/io/error.rs
@@ -9,11 +9,12 @@
 // except according to those terms.
 
 use boxed::Box;
+use convert::Into;
 use error;
 use fmt;
+use marker::Send;
 use option::Option::{self, Some, None};
 use result;
-use string::String;
 use sys;
 
 /// A type for results generated by I/O related functions where the `Err` type
@@ -30,23 +31,22 @@ pub type Result<T> = result::Result<T, Error>;
 /// Errors mostly originate from the underlying OS, but custom instances of
 /// `Error` can be created with crafted error messages and a particular value of
 /// `ErrorKind`.
-#[derive(PartialEq, Eq, Clone, Debug)]
+#[derive(Debug)]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct Error {
     repr: Repr,
 }
 
-#[derive(PartialEq, Eq, Clone, Debug)]
+#[derive(Debug)]
 enum Repr {
     Os(i32),
     Custom(Box<Custom>),
 }
 
-#[derive(PartialEq, Eq, Clone, Debug)]
+#[derive(Debug)]
 struct Custom {
     kind: ErrorKind,
-    desc: &'static str,
-    detail: Option<String>
+    error: Box<error::Error+Send>,
 }
 
 /// A list specifying general categories of I/O error.
@@ -124,18 +124,34 @@ pub enum ErrorKind {
 }
 
 impl Error {
-    /// Creates a new custom error from a specified kind/description/detail.
-    #[unstable(feature = "io", reason = "the exact makeup of an Error may
-                                         change to include `Box<Error>` for \
-                                         example")]
-    pub fn new(kind: ErrorKind,
-               description: &'static str,
-               detail: Option<String>) -> Error {
+    /// Creates a new I/O error from a known kind of error as well as an
+    /// arbitrary error payload.
+    ///
+    /// This function is used to generically create I/O errors which do not
+    /// originate from the OS itself. The `error` argument is an arbitrary
+    /// payload which will be contained in this `Error`. Accessors as well as
+    /// downcasting will soon be added to this type as well to access the custom
+    /// information.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::io::{Error, ErrorKind};
+    ///
+    /// // errors can be created from strings
+    /// let custom_error = Error::new(ErrorKind::Other, "oh no!");
+    ///
+    /// // errors can also be created from other errors
+    /// let custom_error2 = Error::new(ErrorKind::Interrupted, custom_error);
+    /// ```
+    #[stable(feature = "rust1", since = "1.0.0")]
+    pub fn new<E>(kind: ErrorKind, error: E) -> Error
+        where E: Into<Box<error::Error+Send>>
+    {
         Error {
             repr: Repr::Custom(Box::new(Custom {
                 kind: kind,
-                desc: description,
-                detail: detail,
+                error: error.into(),
             }))
         }
     }
@@ -161,8 +177,7 @@ impl Error {
     ///
     /// If this `Error` was constructed via `last_os_error` then this function
     /// will return `Some`, otherwise it will return `None`.
-    #[unstable(feature = "io", reason = "function was just added and the return \
-                                         type may become an abstract OS error")]
+    #[stable(feature = "rust1", since = "1.0.0")]
     pub fn raw_os_error(&self) -> Option<i32> {
         match self.repr {
             Repr::Os(i) => Some(i),
@@ -188,21 +203,7 @@ impl fmt::Display for Error {
                 let detail = sys::os::error_string(code);
                 write!(fmt, "{} (os error {})", detail, code)
             }
-            Repr::Custom(ref c) => {
-                match **c {
-                    Custom {
-                        kind: ErrorKind::Other,
-                        desc: "unknown error",
-                        detail: Some(ref detail)
-                    } => {
-                        write!(fmt, "{}", detail)
-                    }
-                    Custom { detail: None, desc, .. } =>
-                        write!(fmt, "{}", desc),
-                    Custom { detail: Some(ref detail), desc, .. } =>
-                        write!(fmt, "{} ({})", desc, detail)
-                }
-            }
+            Repr::Custom(ref c) => c.error.fmt(fmt),
         }
     }
 }
@@ -212,7 +213,7 @@ impl error::Error for Error {
     fn description(&self) -> &str {
         match self.repr {
             Repr::Os(..) => "os error",
-            Repr::Custom(ref c) => c.desc,
+            Repr::Custom(ref c) => c.error.description(),
         }
     }
 }
diff --git a/src/libstd/io/impls.rs b/src/libstd/io/impls.rs
index 52daba36213..67bc45d3b62 100644
--- a/src/libstd/io/impls.rs
+++ b/src/libstd/io/impls.rs
@@ -180,7 +180,7 @@ impl<'a> Write for &'a mut [u8] {
         if try!(self.write(data)) == data.len() {
             Ok(())
         } else {
-            Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer", None))
+            Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer"))
         }
     }
 
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs
index 0e379b5ab43..d72abe8c69b 100644
--- a/src/libstd/io/mod.rs
+++ b/src/libstd/io/mod.rs
@@ -83,7 +83,7 @@ fn append_to_string<F>(buf: &mut String, f: F) -> Result<usize>
         if str::from_utf8(&g.s[g.len..]).is_err() {
             ret.and_then(|_| {
                 Err(Error::new(ErrorKind::InvalidInput,
-                               "stream did not contain valid UTF-8", None))
+                               "stream did not contain valid UTF-8"))
             })
         } else {
             g.len = g.s.len();
@@ -359,8 +359,7 @@ pub trait Write {
         while buf.len() > 0 {
             match self.write(buf) {
                 Ok(0) => return Err(Error::new(ErrorKind::WriteZero,
-                                               "failed to write whole buffer",
-                                               None)),
+                                               "failed to write whole buffer")),
                 Ok(n) => buf = &buf[n..],
                 Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
                 Err(e) => return Err(e),
@@ -782,7 +781,7 @@ pub struct Chars<R> {
 
 /// An enumeration of possible errors that can be generated from the `Chars`
 /// adapter.
-#[derive(PartialEq, Clone, Debug)]
+#[derive(Debug)]
 #[unstable(feature = "io", reason = "awaiting stability of Read::chars")]
 pub enum CharsError {
     /// Variant representing that the underlying stream was read successfully
diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs
index a08b33b342b..eb6cb441606 100644
--- a/src/libstd/net/addr.rs
+++ b/src/libstd/net/addr.rs
@@ -435,7 +435,7 @@ impl ToSocketAddrs for str {
                 match $e {
                     Some(r) => r,
                     None => return Err(io::Error::new(io::ErrorKind::InvalidInput,
-                                                      $msg, None)),
+                                                      $msg)),
                 }
             )
         }
diff --git a/src/libstd/net/mod.rs b/src/libstd/net/mod.rs
index ee57300765e..a152b98822a 100644
--- a/src/libstd/net/mod.rs
+++ b/src/libstd/net/mod.rs
@@ -72,7 +72,7 @@ fn each_addr<A: ToSocketAddrs, F, T>(addr: A, mut f: F) -> io::Result<T>
     }
     Err(last_err.unwrap_or_else(|| {
         Error::new(ErrorKind::InvalidInput,
-                   "could not resolve to any addresses", None)
+                   "could not resolve to any addresses")
     }))
 }
 
diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs
index 497e6bcbd71..14b5c974b67 100644
--- a/src/libstd/net/udp.rs
+++ b/src/libstd/net/udp.rs
@@ -76,7 +76,7 @@ impl UdpSocket {
         match try!(addr.to_socket_addrs()).next() {
             Some(addr) => self.0.send_to(buf, &addr),
             None => Err(Error::new(ErrorKind::InvalidInput,
-                                   "no addresses to send data to", None)),
+                                   "no addresses to send data to")),
         }
     }
 
diff --git a/src/libstd/process.rs b/src/libstd/process.rs
index 63023855514..ca25cadb9dc 100644
--- a/src/libstd/process.rs
+++ b/src/libstd/process.rs
@@ -456,7 +456,6 @@ impl Child {
             return Err(Error::new(
                 ErrorKind::InvalidInput,
                 "invalid argument: can't kill an exited process",
-                None
             ))
         }
 
diff --git a/src/libstd/sys/common/net2.rs b/src/libstd/sys/common/net2.rs
index e787442052d..7d42d65d360 100644
--- a/src/libstd/sys/common/net2.rs
+++ b/src/libstd/sys/common/net2.rs
@@ -75,7 +75,7 @@ fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
             })))
         }
         _ => {
-            Err(Error::new(ErrorKind::InvalidInput, "invalid argument", None))
+            Err(Error::new(ErrorKind::InvalidInput, "invalid argument"))
         }
     }
 }
@@ -158,8 +158,7 @@ pub fn lookup_addr(addr: &IpAddr) -> io::Result<String> {
     match from_utf8(data.to_bytes()) {
         Ok(name) => Ok(name.to_string()),
         Err(_) => Err(io::Error::new(io::ErrorKind::Other,
-                                     "failed to lookup address information",
-                                     Some("invalid host name".to_string())))
+                                     "failed to lookup address information"))
     }
 }
 
diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs
index 00b907ce10c..908136a42ab 100644
--- a/src/libstd/sys/unix/net.rs
+++ b/src/libstd/sys/unix/net.rs
@@ -35,7 +35,8 @@ pub fn cvt_gai(err: c_int) -> io::Result<()> {
             .to_string()
     };
     Err(io::Error::new(io::ErrorKind::Other,
-                       "failed to lookup address information", Some(detail)))
+                       &format!("failed to lookup address information: {}",
+                                detail)[..]))
 }
 
 impl Socket {