Skip to content

Commit

Permalink
Flag Result as #[must_use] and deal with fallout.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Jan 29, 2014
1 parent 9896beb commit c13a625
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 21 deletions.
22 changes: 10 additions & 12 deletions src/libnative/io/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
}
}
}

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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 {
Expand All @@ -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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libnative/io/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/libnative/io/timer_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/libnative/io/timer_other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {}
Expand Down
4 changes: 2 additions & 2 deletions src/libnative/io/timer_timerfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ 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];
// drain the timerfd of how many times its fired
//
// 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
Expand Down
2 changes: 1 addition & 1 deletion src/librustuv/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/io/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/libstd/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

5 comments on commit c13a625

@bors
Copy link
Contributor

@bors bors commented on c13a625 Jan 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@c13a625

@bors
Copy link
Contributor

@bors bors commented on c13a625 Jan 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/unused-result = c13a625 into auto

@bors
Copy link
Contributor

@bors bors commented on c13a625 Jan 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/unused-result = c13a625 merged ok, testing candidate = c3ae182

@bors
Copy link
Contributor

@bors bors commented on c13a625 Jan 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on c13a625 Jan 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c3ae182

Please sign in to comment.