From 94f2dfa8f632542bfb7260ca4b0aadce24061592 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 30 Jan 2014 14:28:36 -0800 Subject: [PATCH] rustuv: Require all results are used and fix fallout --- src/librustuv/file.rs | 9 +++++---- src/librustuv/homing.rs | 4 ++-- src/librustuv/idle.rs | 4 ++-- src/librustuv/lib.rs | 5 +++-- src/librustuv/macros.rs | 6 +++--- src/librustuv/net.rs | 12 ++++++------ src/librustuv/pipe.rs | 2 +- src/librustuv/queue.rs | 2 +- src/librustuv/signal.rs | 2 +- src/librustuv/timer.rs | 18 +++++++++--------- src/librustuv/uvio.rs | 2 +- 11 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/librustuv/file.rs b/src/librustuv/file.rs index 31afa7b5c7c8..2cef2664c2fc 100644 --- a/src/librustuv/file.rs +++ b/src/librustuv/file.rs @@ -140,9 +140,9 @@ impl FsRequest { let mut paths = ~[]; let path = CString::new(path.with_ref(|p| p), false); let parent = Path::new(path); - c_str::from_c_multistring(req.get_ptr() as *libc::c_char, - Some(req.get_result() as uint), - |rel| { + let _ = c_str::from_c_multistring(req.get_ptr() as *libc::c_char, + Some(req.get_result() as uint), + |rel| { let p = rel.as_bytes(); paths.push(parent.join(p.slice_to(rel.len()))); }); @@ -378,7 +378,8 @@ impl Drop for FileWatcher { rtio::CloseAsynchronously => { unsafe { let req = uvll::malloc_req(uvll::UV_FS); - uvll::uv_fs_close(self.loop_.handle, req, self.fd, close_cb); + assert_eq!(uvll::uv_fs_close(self.loop_.handle, req, + self.fd, close_cb), 0); } extern fn close_cb(req: *uvll::uv_fs_t) { diff --git a/src/librustuv/homing.rs b/src/librustuv/homing.rs index 8d3e71312cd9..a2f3457a9430 100644 --- a/src/librustuv/homing.rs +++ b/src/librustuv/homing.rs @@ -176,7 +176,7 @@ mod test { }); let task = pool.task(TaskOpts::new(), proc() { - port.recv(); + drop(port.recv()); }); pool.spawn_sched().send(sched::TaskFromFriend(task)); @@ -197,7 +197,7 @@ mod test { let listener = UdpWatcher::bind(local_loop(), addr2); chan.send((listener.unwrap(), addr1)); let mut listener = UdpWatcher::bind(local_loop(), addr1).unwrap(); - listener.sendto([1, 2, 3, 4], addr2); + listener.sendto([1, 2, 3, 4], addr2).unwrap(); }); let task = pool.task(TaskOpts::new(), proc() { diff --git a/src/librustuv/idle.rs b/src/librustuv/idle.rs index 3d6e81d0d6fd..dafd3dbe1bc9 100644 --- a/src/librustuv/idle.rs +++ b/src/librustuv/idle.rs @@ -52,7 +52,7 @@ impl IdleWatcher { let data = uvll::get_data_for_uv_handle(handle); let f: ~proc() = cast::transmute(data); (*f)(); - uvll::uv_idle_stop(handle); + assert_eq!(uvll::uv_idle_stop(handle), 0); uvll::uv_close(handle, close_cb); } } @@ -122,7 +122,7 @@ mod test { } } }; - task.wake().map(|t| t.reawaken(true)); + let _ = task.wake().map(|t| t.reawaken(true)); } } diff --git a/src/librustuv/lib.rs b/src/librustuv/lib.rs index 0b889e17a445..f945c0972ca3 100644 --- a/src/librustuv/lib.rs +++ b/src/librustuv/lib.rs @@ -40,6 +40,7 @@ via `close` and `delete` methods. #[crate_type = "dylib"]; #[feature(macro_rules)]; +#[deny(unused_result, unused_must_use)]; #[cfg(test)] extern mod green; @@ -207,7 +208,7 @@ fn wait_until_woken_after(slot: *mut Option, f: ||) { fn wakeup(slot: &mut Option) { assert!(slot.is_some()); - slot.take_unwrap().wake().map(|t| t.reawaken(true)); + let _ = slot.take_unwrap().wake().map(|t| t.reawaken(true)); } pub struct Request { @@ -276,7 +277,7 @@ impl Loop { pub fn wrap(handle: *uvll::uv_loop_t) -> Loop { Loop { handle: handle } } pub fn run(&mut self) { - unsafe { uvll::uv_run(self.handle, uvll::RUN_DEFAULT) }; + assert_eq!(unsafe { uvll::uv_run(self.handle, uvll::RUN_DEFAULT) }, 0); } pub fn close(&mut self) { diff --git a/src/librustuv/macros.rs b/src/librustuv/macros.rs index afd36f8ddd17..75b68e3a5288 100644 --- a/src/librustuv/macros.rs +++ b/src/librustuv/macros.rs @@ -34,11 +34,11 @@ pub fn dumb_println(args: &fmt::Arguments) { struct Stderr; impl io::Writer for Stderr { fn write(&mut self, data: &[u8]) -> io::IoResult<()> { - unsafe { + let _ = unsafe { libc::write(libc::STDERR_FILENO, data.as_ptr() as *libc::c_void, - data.len() as libc::size_t); - } + data.len() as libc::size_t) + }; Ok(()) // just ignore the errors } } diff --git a/src/librustuv/net.rs b/src/librustuv/net.rs index 8919ecfa97ef..5461fc6272d3 100644 --- a/src/librustuv/net.rs +++ b/src/librustuv/net.rs @@ -953,11 +953,11 @@ mod test { spawn(proc() { let port2 = port.recv(); let mut stream = TcpWatcher::connect(local_loop(), addr).unwrap(); - stream.write([0, 1, 2, 3, 4, 5, 6, 7]); - stream.write([0, 1, 2, 3, 4, 5, 6, 7]); + stream.write([0, 1, 2, 3, 4, 5, 6, 7]).unwrap(); + stream.write([0, 1, 2, 3, 4, 5, 6, 7]).unwrap(); port2.recv(); - stream.write([0, 1, 2, 3, 4, 5, 6, 7]); - stream.write([0, 1, 2, 3, 4, 5, 6, 7]); + stream.write([0, 1, 2, 3, 4, 5, 6, 7]).unwrap(); + stream.write([0, 1, 2, 3, 4, 5, 6, 7]).unwrap(); port2.recv(); }); @@ -1008,7 +1008,7 @@ mod test { while stream.is_err() { stream = TcpWatcher::connect(local_loop(), addr); } - stream.unwrap().write([0, 1, 2, 3, 4, 5, 6, 7]); + stream.unwrap().write([0, 1, 2, 3, 4, 5, 6, 7]).unwrap(); } #[should_fail] #[test] @@ -1028,7 +1028,7 @@ mod test { let w = TcpListener::bind(local_loop(), addr).unwrap(); let mut w = w.listen().unwrap(); chan.send(()); - w.accept(); + drop(w.accept().unwrap()); }); port.recv(); let _w = TcpWatcher::connect(local_loop(), addr).unwrap(); diff --git a/src/librustuv/pipe.rs b/src/librustuv/pipe.rs index cfe86d739abc..a021a13e2d98 100644 --- a/src/librustuv/pipe.rs +++ b/src/librustuv/pipe.rs @@ -306,7 +306,7 @@ mod tests { let p = PipeListener::bind(local_loop(), &path2.to_c_str()).unwrap(); let mut p = p.listen().unwrap(); chan.send(()); - p.accept(); + drop(p.accept().unwrap()); }); port.recv(); let _c = PipeWatcher::connect(local_loop(), &path.to_c_str()).unwrap(); diff --git a/src/librustuv/queue.rs b/src/librustuv/queue.rs index 32f8d8532a20..0e1c4225caa9 100644 --- a/src/librustuv/queue.rs +++ b/src/librustuv/queue.rs @@ -67,7 +67,7 @@ extern fn async_cb(handle: *uvll::uv_async_t, status: c_int) { loop { match state.consumer.pop() { mpsc::Data(Task(task)) => { - task.wake().map(|t| t.reawaken(true)); + let _ = task.wake().map(|t| t.reawaken(true)); } mpsc::Data(Increment) => unsafe { if state.refcnt == 0 { diff --git a/src/librustuv/signal.rs b/src/librustuv/signal.rs index 8cb0c1f0a52d..2fcc61be79bd 100644 --- a/src/librustuv/signal.rs +++ b/src/librustuv/signal.rs @@ -86,7 +86,7 @@ mod test { chan); spawn(proc() { - port.try_recv(); + let _ = port.recv_opt(); }); // when we drop the SignalWatcher we're going to destroy the channel, diff --git a/src/librustuv/timer.rs b/src/librustuv/timer.rs index aeda1a45175e..792414238fda 100644 --- a/src/librustuv/timer.rs +++ b/src/librustuv/timer.rs @@ -138,11 +138,11 @@ extern fn timer_cb(handle: *uvll::uv_timer_t, status: c_int) { match timer.action.take_unwrap() { WakeTask(task) => { - task.wake().map(|t| t.reawaken(true)); + let _ = task.wake().map(|t| t.reawaken(true)); } - SendOnce(chan) => { chan.try_send(()); } + SendOnce(chan) => { let _ = chan.try_send(()); } SendMany(chan, id) => { - chan.try_send(()); + let _ = chan.try_send(()); // Note that the above operation could have performed some form of // scheduling. This means that the timer may have decided to insert @@ -246,7 +246,7 @@ mod test { let timer_port = timer.period(1000); spawn(proc() { - timer_port.recv_opt(); + let _ = timer_port.recv_opt(); }); // when we drop the TimerWatcher we're going to destroy the channel, @@ -260,10 +260,10 @@ mod test { let timer_port = timer.period(1000); spawn(proc() { - timer_port.recv_opt(); + let _ = timer_port.recv_opt(); }); - timer.oneshot(1); + drop(timer.oneshot(1)); } #[test] fn reset_doesnt_switch_tasks2() { @@ -272,7 +272,7 @@ mod test { let timer_port = timer.period(1000); spawn(proc() { - timer_port.recv_opt(); + let _ = timer_port.recv_opt(); }); timer.sleep(1); @@ -299,7 +299,7 @@ mod test { #[test] fn receiver_goes_away_oneshot() { let mut timer1 = TimerWatcher::new(local_loop()); - timer1.oneshot(1); + drop(timer1.oneshot(1)); let mut timer2 = TimerWatcher::new(local_loop()); // while sleeping, the prevous timer should fire and not have its // callback do something terrible. @@ -309,7 +309,7 @@ mod test { #[test] fn receiver_goes_away_period() { let mut timer1 = TimerWatcher::new(local_loop()); - timer1.period(1); + drop(timer1.period(1)); let mut timer2 = TimerWatcher::new(local_loop()); // while sleeping, the prevous timer should fire and not have its // callback do something terrible. diff --git a/src/librustuv/uvio.rs b/src/librustuv/uvio.rs index e0bff059b0c9..8a8ef4a41ec4 100644 --- a/src/librustuv/uvio.rs +++ b/src/librustuv/uvio.rs @@ -71,7 +71,7 @@ impl Drop for UvEventLoop { // after the loop has been closed because during the closing of the loop // the handle is required to be used apparently. let handle = self.uvio.handle_pool.get_ref().handle(); - self.uvio.handle_pool.take(); + drop(self.uvio.handle_pool.take()); self.uvio.loop_.close(); unsafe { uvll::free_handle(handle) } }