Flag Result as #[must_use] and deal with fallout.

This commit is contained in:
Alex Crichton 2014-01-23 09:53:05 -08:00
parent 9896beb5b5
commit c13a62593c
8 changed files with 20 additions and 21 deletions

View File

@ -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<int, IoError> {
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<u64, IoError> {
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))
}
}

View File

@ -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();
})
}

View File

@ -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) {

View File

@ -187,7 +187,7 @@ fn helper(input: libc::c_int, messages: Port<Req>) {
// 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 => {}

View File

@ -98,7 +98,7 @@ fn helper(input: libc::c_int, messages: Port<Req>) {
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<Req>) {
//
// 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

View File

@ -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)
});
}

View File

@ -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.

View File

@ -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<T, E> {
/// Contains the success value
Ok(T),