Skip to content

Commit ae581a0

Browse files
committed
native: Require all results are used and fix fallout
1 parent 41cde56 commit ae581a0

File tree

7 files changed

+26
-22
lines changed

7 files changed

+26
-22
lines changed

src/libnative/bookkeeping.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static mut TASK_COUNT: atomics::AtomicUint = atomics::INIT_ATOMIC_UINT;
2323
static mut TASK_LOCK: Mutex = MUTEX_INIT;
2424

2525
pub fn increment() {
26-
unsafe { TASK_COUNT.fetch_add(1, atomics::SeqCst); }
26+
let _ = unsafe { TASK_COUNT.fetch_add(1, atomics::SeqCst) };
2727
}
2828

2929
pub fn decrement() {

src/libnative/io/file.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ impl rtio::RtioFileStream for CFile {
422422

423423
impl Drop for CFile {
424424
fn drop(&mut self) {
425-
unsafe { libc::fclose(self.file); }
425+
unsafe { let _ = libc::fclose(self.file); }
426426
}
427427
}
428428

@@ -512,7 +512,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
512512
paths.push(Path::new(cstr));
513513
entry_ptr = readdir(dir_ptr);
514514
}
515-
closedir(dir_ptr);
515+
assert_eq!(closedir(dir_ptr), 0);
516516
Ok(paths)
517517
} else {
518518
Err(super::last_error())
@@ -932,7 +932,7 @@ mod tests {
932932
let mut reader = FileDesc::new(input, true);
933933
let mut writer = FileDesc::new(out, true);
934934

935-
writer.inner_write(bytes!("test"));
935+
writer.inner_write(bytes!("test")).unwrap();
936936
let mut buf = [0u8, ..4];
937937
match reader.inner_read(buf) {
938938
Ok(4) => {
@@ -957,9 +957,9 @@ mod tests {
957957
assert!(!f.is_null());
958958
let mut file = CFile::new(f);
959959

960-
file.write(bytes!("test"));
960+
file.write(bytes!("test")).unwrap();
961961
let mut buf = [0u8, ..4];
962-
file.seek(0, io::SeekSet);
962+
let _ = file.seek(0, io::SeekSet).unwrap();
963963
match file.read(buf) {
964964
Ok(4) => {
965965
assert_eq!(buf[0], 't' as u8);

src/libnative/io/net.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ fn setsockopt<T>(fd: sock_t, opt: libc::c_int, val: libc::c_int,
112112
}
113113
}
114114

115-
#[cfg(windows)] unsafe fn close(sock: sock_t) { libc::closesocket(sock); }
116-
#[cfg(unix)] unsafe fn close(sock: sock_t) { libc::close(sock); }
115+
#[cfg(windows)] unsafe fn close(sock: sock_t) { let _ = libc::closesocket(sock); }
116+
#[cfg(unix)] unsafe fn close(sock: sock_t) { let _ = libc::close(sock); }
117117

118118
fn sockname(fd: sock_t,
119119
f: extern "system" unsafe fn(sock_t, *mut libc::sockaddr,

src/libnative/io/process.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ impl Process {
102102
cwd.as_ref(), in_fd, out_fd, err_fd);
103103

104104
unsafe {
105-
for pipe in in_pipe.iter() { libc::close(pipe.input); }
106-
for pipe in out_pipe.iter() { libc::close(pipe.out); }
107-
for pipe in err_pipe.iter() { libc::close(pipe.out); }
105+
for pipe in in_pipe.iter() { let _ = libc::close(pipe.input); }
106+
for pipe in out_pipe.iter() { let _ = libc::close(pipe.out); }
107+
for pipe in err_pipe.iter() { let _ = libc::close(pipe.out); }
108108
}
109109

110110
match res {
@@ -163,8 +163,8 @@ impl rtio::RtioProcess for Process {
163163

164164
#[cfg(not(windows))]
165165
unsafe fn killpid(pid: pid_t, signal: int) -> Result<(), io::IoError> {
166-
libc::funcs::posix88::signal::kill(pid, signal as c_int);
167-
Ok(())
166+
let r = libc::funcs::posix88::signal::kill(pid, signal as c_int);
167+
super::mkerr_libc(r)
168168
}
169169
}
170170
}
@@ -445,24 +445,24 @@ fn spawn_process_os(prog: &str, args: &[~str],
445445
rustrt::rust_unset_sigprocmask();
446446

447447
if in_fd == -1 {
448-
libc::close(libc::STDIN_FILENO);
448+
let _ = libc::close(libc::STDIN_FILENO);
449449
} else if retry(|| dup2(in_fd, 0)) == -1 {
450450
fail!("failure in dup2(in_fd, 0): {}", os::last_os_error());
451451
}
452452
if out_fd == -1 {
453-
libc::close(libc::STDOUT_FILENO);
453+
let _ = libc::close(libc::STDOUT_FILENO);
454454
} else if retry(|| dup2(out_fd, 1)) == -1 {
455455
fail!("failure in dup2(out_fd, 1): {}", os::last_os_error());
456456
}
457457
if err_fd == -1 {
458-
libc::close(libc::STDERR_FILENO);
458+
let _ = libc::close(libc::STDERR_FILENO);
459459
} else if retry(|| dup2(err_fd, 2)) == -1 {
460460
fail!("failure in dup3(err_fd, 2): {}", os::last_os_error());
461461
}
462462
// close all other fds
463463
for fd in range(3, getdtablesize()).rev() {
464464
if fd != output.fd() {
465-
close(fd as c_int);
465+
let _ = close(fd as c_int);
466466
}
467467
}
468468

@@ -478,7 +478,7 @@ fn spawn_process_os(prog: &str, args: &[~str],
478478
}
479479
});
480480
with_argv(prog, args, |argv| {
481-
execvp(*argv, argv);
481+
let _ = execvp(*argv, argv);
482482
let errno = os::errno();
483483
let bytes = [
484484
(errno << 24) as u8,

src/libnative/io/timer_other.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn helper(input: libc::c_int, messages: Port<Req>) {
187187

188188
// drain the file descriptor
189189
let mut buf = [0];
190-
fd.inner_read(buf).unwrap();
190+
assert_eq!(fd.inner_read(buf).unwrap(), 1);
191191
}
192192

193193
-1 if os::errno() == libc::EINTR as int => {}
@@ -216,7 +216,8 @@ impl Timer {
216216
}
217217

218218
pub fn sleep(ms: u64) {
219-
unsafe { libc::usleep((ms * 1000) as libc::c_uint); }
219+
// FIXME: this can fail because of EINTR, what do do?
220+
let _ = unsafe { libc::usleep((ms * 1000) as libc::c_uint) };
220221
}
221222

222223
fn inner(&mut self) -> ~Inner {

src/libnative/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#[doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
2222
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2323
html_root_url = "http://static.rust-lang.org/doc/master")];
24+
#[deny(unused_result, unused_must_use)];
2425

2526
// NB this crate explicitly does *not* allow glob imports, please seriously
2627
// consider whether they're needed before adding that feature here (the
@@ -61,9 +62,10 @@ pub fn start(argc: int, argv: **u8, main: proc()) -> int {
6162
rt::init(argc, argv);
6263
let mut exit_code = None;
6364
let mut main = Some(main);
64-
task::new((my_stack_bottom, my_stack_top)).run(|| {
65+
let t = task::new((my_stack_bottom, my_stack_top)).run(|| {
6566
exit_code = Some(run(main.take_unwrap()));
6667
});
68+
drop(t);
6769
unsafe { rt::cleanup(); }
6870
// If the exit code wasn't set, then the task block must have failed.
6971
return exit_code.unwrap_or(rt::DEFAULT_ERROR_CODE);

src/libnative/task.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ pub fn spawn_opts(opts: TaskOpts, f: proc()) {
103103
let mut f = Some(f);
104104
let mut task = task;
105105
task.put_runtime(ops as ~rt::Runtime);
106-
task.run(|| { f.take_unwrap()() });
106+
let t = task.run(|| { f.take_unwrap()() });
107+
drop(t);
107108
bookkeeping::decrement();
108109
})
109110
}

0 commit comments

Comments
 (0)