From c13a62593c218243b4d3b0e8be0b903c0315571b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 23 Jan 2014 09:53:05 -0800 Subject: [PATCH] Flag Result as #[must_use] and deal with fallout. --- src/libnative/io/file.rs | 22 ++++++++++------------ src/libnative/io/process.rs | 2 +- src/libnative/io/timer_helper.rs | 2 +- src/libnative/io/timer_other.rs | 2 +- src/libnative/io/timer_timerfd.rs | 4 ++-- src/librustuv/file.rs | 2 +- src/libstd/io/fs.rs | 6 +++--- src/libstd/result.rs | 1 + 8 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/libnative/io/file.rs b/src/libnative/io/file.rs index 53386433d53..acab7ce3a91 100644 --- a/src/libnative/io/file.rs +++ b/src/libnative/io/file.rs @@ -118,7 +118,10 @@ impl io::Reader for FileDesc { impl io::Writer for FileDesc { fn write(&mut self, buf: &[u8]) { - self.inner_write(buf); + match self.inner_write(buf) { + Ok(()) => {} + Err(e) => { io::io_error::cond.raise(e); } + } } } @@ -276,7 +279,7 @@ impl rtio::RtioFileStream for FileDesc { _ => Ok(()) } }; - self.seek(orig_pos as i64, io::SeekSet); + let _ = self.seek(orig_pos as i64, io::SeekSet); return ret; } #[cfg(unix)] @@ -383,12 +386,10 @@ impl rtio::RtioFileStream for CFile { } fn pread(&mut self, buf: &mut [u8], offset: u64) -> Result { - self.flush(); - self.fd.pread(buf, offset) + self.flush().and_then(|()| self.fd.pread(buf, offset)) } fn pwrite(&mut self, buf: &[u8], offset: u64) -> Result<(), IoError> { - self.flush(); - self.fd.pwrite(buf, offset) + self.flush().and_then(|()| self.fd.pwrite(buf, offset)) } fn seek(&mut self, pos: i64, style: io::SeekStyle) -> Result { let whence = match style { @@ -412,16 +413,13 @@ impl rtio::RtioFileStream for CFile { } } fn fsync(&mut self) -> Result<(), IoError> { - self.flush(); - self.fd.fsync() + self.flush().and_then(|()| self.fd.fsync()) } fn datasync(&mut self) -> Result<(), IoError> { - self.flush(); - self.fd.fsync() + self.flush().and_then(|()| self.fd.fsync()) } fn truncate(&mut self, offset: i64) -> Result<(), IoError> { - self.flush(); - self.fd.truncate(offset) + self.flush().and_then(|()| self.fd.truncate(offset)) } } diff --git a/src/libnative/io/process.rs b/src/libnative/io/process.rs index ee4ee295055..13dd4298777 100644 --- a/src/libnative/io/process.rs +++ b/src/libnative/io/process.rs @@ -486,7 +486,7 @@ fn spawn_process_os(prog: &str, args: &[~str], (errno << 8) as u8, (errno << 0) as u8, ]; - output.inner_write(bytes); + assert!(output.inner_write(bytes).is_ok()); intrinsics::abort(); }) } diff --git a/src/libnative/io/timer_helper.rs b/src/libnative/io/timer_helper.rs index 3c20d073f29..9297679857b 100644 --- a/src/libnative/io/timer_helper.rs +++ b/src/libnative/io/timer_helper.rs @@ -101,7 +101,7 @@ mod imp { } pub fn signal(fd: libc::c_int) { - FileDesc::new(fd, false).inner_write([0]); + FileDesc::new(fd, false).inner_write([0]).unwrap(); } pub fn close(fd: libc::c_int) { diff --git a/src/libnative/io/timer_other.rs b/src/libnative/io/timer_other.rs index 4a62a400c8d..bc005f2fe8d 100644 --- a/src/libnative/io/timer_other.rs +++ b/src/libnative/io/timer_other.rs @@ -187,7 +187,7 @@ fn helper(input: libc::c_int, messages: Port) { // drain the file descriptor let mut buf = [0]; - fd.inner_read(buf); + fd.inner_read(buf).unwrap(); } -1 if os::errno() == libc::EINTR as int => {} diff --git a/src/libnative/io/timer_timerfd.rs b/src/libnative/io/timer_timerfd.rs index 2bcaf4d5c7c..1888b8578a0 100644 --- a/src/libnative/io/timer_timerfd.rs +++ b/src/libnative/io/timer_timerfd.rs @@ -98,7 +98,7 @@ fn helper(input: libc::c_int, messages: Port) { if fd == input { let mut buf = [0, ..1]; // drain the input file descriptor of its input - FileDesc::new(fd, false).inner_read(buf); + FileDesc::new(fd, false).inner_read(buf).unwrap(); incoming = true; } else { let mut bits = [0, ..8]; @@ -106,7 +106,7 @@ fn helper(input: libc::c_int, messages: Port) { // // FIXME: should this perform a send() this number of // times? - FileDesc::new(fd, false).inner_read(bits); + FileDesc::new(fd, false).inner_read(bits).unwrap(); let remove = { match map.find(&fd).expect("fd unregistered") { &(ref c, oneshot) => !c.try_send(()) || oneshot diff --git a/src/librustuv/file.rs b/src/librustuv/file.rs index 8f7ced93fb0..31afa7b5c7c 100644 --- a/src/librustuv/file.rs +++ b/src/librustuv/file.rs @@ -389,7 +389,7 @@ impl Drop for FileWatcher { } } rtio::CloseSynchronously => { - execute_nop(|req, cb| unsafe { + let _ = execute_nop(|req, cb| unsafe { uvll::uv_fs_close(self.loop_.handle, req, self.fd, cb) }); } diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index cb98ff21105..8904101dd05 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -175,7 +175,7 @@ impl File { /// /// This function will raise on the `io_error` condition on failure. pub fn fsync(&mut self) { - self.fd.fsync().map_err(|e| io_error::cond.raise(e)); + let _ = self.fd.fsync().map_err(|e| io_error::cond.raise(e)); } /// This function is similar to `fsync`, except that it may not synchronize @@ -187,7 +187,7 @@ impl File { /// /// This function will raise on the `io_error` condition on failure. pub fn datasync(&mut self) { - self.fd.datasync().map_err(|e| io_error::cond.raise(e)); + let _ = self.fd.datasync().map_err(|e| io_error::cond.raise(e)); } /// Either truncates or extends the underlying file, updating the size of @@ -203,7 +203,7 @@ impl File { /// /// On error, this function will raise on the `io_error` condition. pub fn truncate(&mut self, size: i64) { - self.fd.truncate(size).map_err(|e| io_error::cond.raise(e)); + let _ = self.fd.truncate(size).map_err(|e| io_error::cond.raise(e)); } /// Tests whether this stream has reached EOF. diff --git a/src/libstd/result.rs b/src/libstd/result.rs index 62049e8b4c9..c3618bad18e 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -20,6 +20,7 @@ use to_str::ToStr; /// `Result` is a type that represents either success (`Ok`) or failure (`Err`). #[deriving(Clone, DeepClone, Eq, Ord, TotalEq, TotalOrd, ToStr)] +#[must_use] pub enum Result { /// Contains the success value Ok(T),