From 8f5470fd2734044e7bea769623dadd38b8cbe1ff Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 27 Aug 2018 07:12:24 -0600 Subject: [PATCH] Reduce warnings --- src/c_str.rs | 4 ---- src/header/arpa_inet/mod.rs | 16 ++++++++-------- src/header/fnmatch/mod.rs | 1 - src/header/setjmp/mod.rs | 3 --- src/header/signal/mod.rs | 2 +- src/header/stdio/mod.rs | 2 +- src/header/stdlib/mod.rs | 2 -- src/header/strings/mod.rs | 4 ++-- src/header/sys_resource/mod.rs | 8 ++++---- src/header/sys_socket/mod.rs | 2 +- src/header/sys_un/mod.rs | 2 -- src/header/sys_wait/mod.rs | 1 + src/header/time/constants.rs | 1 - src/header/time/strftime.rs | 2 +- src/header/unistd/mod.rs | 4 ++-- src/header/wchar/mod.rs | 14 +++++--------- src/header/wchar/utf8.rs | 4 ++-- src/lib.rs | 2 ++ src/platform/linux/mod.rs | 1 - src/platform/pal/mod.rs | 2 +- 20 files changed, 31 insertions(+), 46 deletions(-) diff --git a/src/c_str.rs b/src/c_str.rs index 113015ef46..cb37b89593 100644 --- a/src/c_str.rs +++ b/src/c_str.rs @@ -848,10 +848,6 @@ impl NulError { pub fn into_vec(self) -> Vec { self.1 } - - fn description(&self) -> &str { - "nul byte found in data" - } } impl fmt::Display for NulError { diff --git a/src/header/arpa_inet/mod.rs b/src/header/arpa_inet/mod.rs index b9dc66b834..cca48be4b9 100644 --- a/src/header/arpa_inet/mod.rs +++ b/src/header/arpa_inet/mod.rs @@ -29,8 +29,6 @@ pub extern "C" fn ntohs(netshort: u16) -> u16 { u16::from_be(netshort) } -static mut NTOA_ADDR: [c_char; 16] = [0; 16]; - #[no_mangle] pub unsafe extern "C" fn inet_aton(cp: *const c_char, inp: *mut in_addr) -> c_int { // TODO: octal/hex @@ -39,6 +37,8 @@ pub unsafe extern "C" fn inet_aton(cp: *const c_char, inp: *mut in_addr) -> c_in #[no_mangle] pub unsafe extern "C" fn inet_ntoa(addr: in_addr) -> *const c_char { + static mut NTOA_ADDR: [c_char; 16] = [0; 16]; + inet_ntop( AF_INET, &addr as *const in_addr as *const c_void, @@ -53,7 +53,7 @@ pub unsafe extern "C" fn inet_pton(domain: c_int, src: *const c_char, dest: *mut platform::errno = EAFNOSUPPORT; -1 } else { - let mut s_addr = slice::from_raw_parts_mut( + let s_addr = slice::from_raw_parts_mut( &mut (*(dest as *mut in_addr)).s_addr as *mut _ as *mut u8, 4, ); @@ -97,27 +97,27 @@ pub unsafe extern "C" fn inet_ntop( } } -#[no_mangle] +//#[no_mangle] pub extern "C" fn inet_addr(cp: *const c_char) -> in_addr_t { unimplemented!(); } -#[no_mangle] +//#[no_mangle] pub extern "C" fn inet_lnaof(_in: in_addr) -> in_addr_t { unimplemented!(); } -#[no_mangle] +//#[no_mangle] pub extern "C" fn inet_makeaddr(net: in_addr_t, lna: in_addr_t) -> in_addr { unimplemented!(); } -#[no_mangle] +//#[no_mangle] pub extern "C" fn inet_netof(_in: in_addr) -> in_addr_t { unimplemented!(); } -#[no_mangle] +//#[no_mangle] pub extern "C" fn inet_network(cp: *const c_char) -> in_addr_t { unimplemented!(); } diff --git a/src/header/fnmatch/mod.rs b/src/header/fnmatch/mod.rs index 32819f0a4b..899dbf7b7c 100644 --- a/src/header/fnmatch/mod.rs +++ b/src/header/fnmatch/mod.rs @@ -161,7 +161,6 @@ pub unsafe extern "C" fn fnmatch( return FNM_NOMATCH; } } - unreachable!("nothing should be able to break out of the loop"); } None => return FNM_NOMATCH, // Pattern ended but there's still some input } diff --git a/src/header/setjmp/mod.rs b/src/header/setjmp/mod.rs index 0f6392dc9f..6371c9a58b 100644 --- a/src/header/setjmp/mod.rs +++ b/src/header/setjmp/mod.rs @@ -1,8 +1,5 @@ //! setjmp implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/setjmp.h.html -#![no_std] -#![feature(global_asm)] - macro_rules! platform_specific { ($($arch:expr,$ext:expr;)+) => { $( diff --git a/src/header/signal/mod.rs b/src/header/signal/mod.rs index c9259651d1..2aa9862a10 100644 --- a/src/header/signal/mod.rs +++ b/src/header/signal/mod.rs @@ -74,7 +74,7 @@ pub unsafe extern "C" fn sigaction( } #[no_mangle] -pub extern "C" fn sigaddset(set: *mut sigset_t, mut signo: c_int) -> c_int { +pub extern "C" fn sigaddset(set: *mut sigset_t, signo: c_int) -> c_int { if signo <= 0 || signo as usize > NSIG { unsafe { platform::errno = errno::EINVAL; diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs index 48f3148835..ca4bdc5156 100644 --- a/src/header/stdio/mod.rs +++ b/src/header/stdio/mod.rs @@ -887,7 +887,7 @@ pub extern "C" fn tempnam(_dir: *const c_char, _pfx: *const c_char) -> *mut c_ch pub extern "C" fn tmpfile() -> *mut FILE { let mut file_name = *b"/tmp/tmpfileXXXXXX"; let file_name = file_name.as_mut_ptr() as *mut c_char; - let fd = unsafe { mkstemp(file_name) }; + let fd = mkstemp(file_name); if fd < 0 { return ptr::null_mut(); diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs index 6de7e36f02..a11a06b4e1 100644 --- a/src/header/stdlib/mod.rs +++ b/src/header/stdlib/mod.rs @@ -432,13 +432,11 @@ where #[no_mangle] pub extern "C" fn mktemp(name: *mut c_char) -> *mut c_char { if inner_mktemp(name, 0, || unsafe { - let mut st: stat = mem::uninitialized(); let ret = if Sys::access(name, 0) != 0 && platform::errno == ENOENT { Some(()) } else { None }; - mem::forget(st); ret }).is_none() { diff --git a/src/header/strings/mod.rs b/src/header/strings/mod.rs index a813932530..77eb9ea0b1 100644 --- a/src/header/strings/mod.rs +++ b/src/header/strings/mod.rs @@ -7,8 +7,8 @@ use platform::types::*; #[no_mangle] pub unsafe extern "C" fn bcmp( - mut first: *const c_void, - mut second: *const c_void, + first: *const c_void, + second: *const c_void, n: size_t, ) -> c_int { let first = first as *const c_char; diff --git a/src/header/sys_resource/mod.rs b/src/header/sys_resource/mod.rs index 6afcc6fe9b..f4b7bc29a2 100644 --- a/src/header/sys_resource/mod.rs +++ b/src/header/sys_resource/mod.rs @@ -7,10 +7,10 @@ use platform::types::*; use platform::{Pal, Sys}; // Exported in bits file -const RUSAGE_SELF: c_int = 0; -const RUSAGE_CHILDREN: c_int = -1; -const RUSAGE_BOTH: c_int = -2; -const RUSAGE_THREAD: c_int = 1; +// const RUSAGE_SELF: c_int = 0; +// const RUSAGE_CHILDREN: c_int = -1; +// const RUSAGE_BOTH: c_int = -2; +// const RUSAGE_THREAD: c_int = 1; type rlim_t = u64; diff --git a/src/header/sys_socket/mod.rs b/src/header/sys_socket/mod.rs index 5a305274ef..877b9cae2c 100644 --- a/src/header/sys_socket/mod.rs +++ b/src/header/sys_socket/mod.rs @@ -6,7 +6,7 @@ use platform; use platform::types::*; use platform::{PalSocket, Sys}; -mod constants; +pub mod constants; pub type in_addr_t = [u8; 4]; pub type in_port_t = u16; diff --git a/src/header/sys_un/mod.rs b/src/header/sys_un/mod.rs index 2c0a2c9422..41f55107be 100644 --- a/src/header/sys_un/mod.rs +++ b/src/header/sys_un/mod.rs @@ -1,5 +1,3 @@ -#![no_std] - use header::sys_socket::sa_family_t; use platform::types::*; diff --git a/src/header/sys_wait/mod.rs b/src/header/sys_wait/mod.rs index 346fe67723..4259c48d1b 100644 --- a/src/header/sys_wait/mod.rs +++ b/src/header/sys_wait/mod.rs @@ -15,6 +15,7 @@ pub const WNOWAIT: c_int = 0x1000000; pub const __WNOTHREAD: c_int = 0x20000000; pub const __WALL: c_int = 0x40000000; +#[allow(overflowing_literals)] pub const __WCLONE: c_int = 0x80000000; #[no_mangle] diff --git a/src/header/time/constants.rs b/src/header/time/constants.rs index 45541d4a28..15810f64c6 100644 --- a/src/header/time/constants.rs +++ b/src/header/time/constants.rs @@ -47,7 +47,6 @@ pub(crate) const MON_NAMES: [&str; 12] = [ pub(crate) const CLOCK_REALTIME: clockid_t = 0; pub const CLOCK_MONOTONIC: clockid_t = 1; pub(crate) const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2; -pub(crate) const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3; // Can't be time_t because cbindgen UGH pub(crate) const CLOCKS_PER_SEC: c_long = 1_000_000; diff --git a/src/header/time/strftime.rs b/src/header/time/strftime.rs index 7456ce43b6..d2f6f91100 100644 --- a/src/header/time/strftime.rs +++ b/src/header/time/strftime.rs @@ -7,7 +7,7 @@ use super::tm; pub unsafe fn strftime(w: &mut W, format: *const c_char, t: *const tm) -> size_t { pub unsafe fn inner_strftime( - mut w: &mut W, + w: &mut W, mut format: *const c_char, t: *const tm, ) -> bool { diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 817504658a..0f426a730a 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -195,11 +195,11 @@ pub extern "C" fn getcwd(mut buf: *mut c_char, mut size: size_t) -> *mut c_char } if alloc { - let mut len = stack_buf + let len = stack_buf .iter() .position(|b| *b == 0) .expect("no nul-byte in getcwd string") + 1; - let mut heap_buf = unsafe { platform::alloc(len) as *mut c_char }; + let heap_buf = unsafe { platform::alloc(len) as *mut c_char }; for i in 0..len { unsafe { *heap_buf.offset(i as isize) = stack_buf[i]; diff --git a/src/header/wchar/mod.rs b/src/header/wchar/mod.rs index 9df75f1472..b60232e7d5 100644 --- a/src/header/wchar/mod.rs +++ b/src/header/wchar/mod.rs @@ -4,6 +4,7 @@ use core::ptr; use va_list::VaList as va_list; use header::stdio::*; +use header::stdlib::MB_CUR_MAX; use header::time::*; use platform; use platform::types::*; @@ -12,11 +13,6 @@ mod utf8; const WEOF: wint_t = 0xFFFFFFFFu32; -//Maximum number of bytes in a multibyte character for the current locale -const MB_CUR_MAX: c_int = 4; -//Maximum number of bytes in a multibyte characters for any locale -const MB_LEN_MAX: c_int = 4; - #[repr(C)] #[derive(Clone, Copy)] pub struct mbstate_t; @@ -204,13 +200,13 @@ pub extern "C" fn swprintf( s: *mut wchar_t, n: size_t, format: *const wchar_t, - mut ap: va_list, + ap: va_list, ) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn swscanf(s: *const wchar_t, format: *const wchar_t, mut ap: va_list) -> c_int { +pub extern "C" fn swscanf(s: *const wchar_t, format: *const wchar_t, ap: va_list) -> c_int { unimplemented!(); } @@ -429,11 +425,11 @@ pub extern "C" fn wmemset(ws1: *mut wchar_t, ws2: wchar_t, n: size_t) -> *mut wc } // #[no_mangle] -pub extern "C" fn wprintf(format: *const wchar_t, mut ap: va_list) -> c_int { +pub extern "C" fn wprintf(format: *const wchar_t, ap: va_list) -> c_int { unimplemented!(); } // #[no_mangle] -pub extern "C" fn wscanf(format: *const wchar_t, mut ap: va_list) -> c_int { +pub extern "C" fn wscanf(format: *const wchar_t, ap: va_list) -> c_int { unimplemented!(); } diff --git a/src/header/wchar/utf8.rs b/src/header/wchar/utf8.rs index 1f8e72f03b..fded8d1d86 100644 --- a/src/header/wchar/utf8.rs +++ b/src/header/wchar/utf8.rs @@ -11,7 +11,7 @@ use super::mbstate_t; //It's guaranteed that we don't have any nullpointers here pub unsafe fn mbrtowc(pwc: *mut wchar_t, s: *const c_char, n: usize, ps: *mut mbstate_t) -> usize { - let mut size = str::utf8_char_width(*s as u8); + let size = str::utf8_char_width(*s as u8); if size > n { platform::errno = errno::EILSEQ; return -2isize as usize; @@ -50,7 +50,7 @@ pub unsafe fn wcrtomb(s: *mut c_char, wc: wchar_t, ps: *mut mbstate_t) -> usize let c = dc.unwrap(); let size = c.len_utf8(); - let mut slice = slice::from_raw_parts_mut(s as *mut u8, size); + let slice = slice::from_raw_parts_mut(s as *mut u8, size); c.encode_utf8(slice); diff --git a/src/lib.rs b/src/lib.rs index bc557b0973..90f2507fcd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ #![no_std] #![allow(non_camel_case_types)] +#![allow(non_upper_case_globals)] +#![allow(unused_variables)] #![feature(alloc)] #![feature(allocator_api)] #![feature(const_fn)] diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 5ef98c4626..80061b698e 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -19,7 +19,6 @@ const TIOCGWINSZ: c_ulong = 0x5413; const AT_FDCWD: c_int = -100; const AT_EMPTY_PATH: c_int = 0x1000; const AT_REMOVEDIR: c_int = 0x200; -const AT_SYMLINK_NOFOLLOW: c_int = 0x100; fn e(sys: usize) -> usize { if (sys as isize) < 0 && (sys as isize) >= -256 { diff --git a/src/platform/pal/mod.rs b/src/platform/pal/mod.rs index 4d15c3b26b..b1da6f24d6 100644 --- a/src/platform/pal/mod.rs +++ b/src/platform/pal/mod.rs @@ -124,7 +124,7 @@ pub trait Pal { Self::no_pal("getrusage") } - unsafe fn gethostname(mut name: *mut c_char, len: size_t) -> c_int { + unsafe fn gethostname(name: *mut c_char, len: size_t) -> c_int { Self::no_pal("gethostname") }