Bläddra i källkod

Reduce warnings

Jeremy Soller 6 år sedan
förälder
incheckning
8f5470fd27

+ 0 - 4
src/c_str.rs

@@ -848,10 +848,6 @@ impl NulError {
     pub fn into_vec(self) -> Vec<u8> {
         self.1
     }
-
-    fn description(&self) -> &str {
-        "nul byte found in data"
-    }
 }
 
 impl fmt::Display for NulError {

+ 8 - 8
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!();
 }

+ 0 - 1
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
         }

+ 0 - 3
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;)+) => {
         $(

+ 1 - 1
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;

+ 1 - 1
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();

+ 0 - 2
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()
     {

+ 2 - 2
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;

+ 4 - 4
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;
 

+ 1 - 1
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;

+ 0 - 2
src/header/sys_un/mod.rs

@@ -1,5 +1,3 @@
-#![no_std]
-
 use header::sys_socket::sa_family_t;
 use platform::types::*;
 

+ 1 - 0
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]

+ 0 - 1
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;

+ 1 - 1
src/header/time/strftime.rs

@@ -7,7 +7,7 @@ use super::tm;
 
 pub unsafe fn strftime<W: Write>(w: &mut W, format: *const c_char, t: *const tm) -> size_t {
     pub unsafe fn inner_strftime<W: Write>(
-        mut w: &mut W,
+        w: &mut W,
         mut format: *const c_char,
         t: *const tm,
     ) -> bool {

+ 2 - 2
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];

+ 5 - 9
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!();
 }

+ 2 - 2
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);
 

+ 2 - 0
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)]

+ 0 - 1
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 {

+ 1 - 1
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")
     }