From 20bdf305264ad9f0b5e92912e84bed6fc2e10ab6 Mon Sep 17 00:00:00 2001 From: auronandace Date: Sun, 15 Feb 2026 21:38:08 +0000 Subject: [PATCH 1/2] remove allow warnings and add some lints --- Cargo.toml | 14 +++++++++----- src/header/grp/mod.rs | 3 +-- src/header/unistd/mod.rs | 8 ++++---- src/header/wctype/casecmp.rs | 6 +++--- src/io/mod.rs | 4 ++-- src/lib.rs | 1 - src/platform/linux/mod.rs | 2 +- 7 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1e62d039e3..cb0f88b9f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,16 +20,19 @@ members = [ exclude = ["tests", "dlmalloc-rs"] [workspace.lints.clippy] -cast_lossless = "warn" +cast_lossless = "warn" # TODO review occurrences cast_ptr_alignment = "allow" # TODO change to warn or deny when ready to fix -mut_from_ref = "allow" -ptr_as_ptr = "warn" -ptr_cast_constness = "warn" -ref_as_ptr = "warn" +missing_safety_doc = "allow" # TODO review occurrences +mut_from_ref = "allow" # TODO review occurrences +ptr_as_ptr = "warn" # TODO review occurrences +ptr_cast_constness = "warn" # TODO review occurrences +ref_as_ptr = "warn" # TODO review occurrences zero_ptr = "warn" # must allow on public constants due to cbindgen issue [workspace.lints.rust] dangling_pointers_from_temporaries = "deny" +dead_code = "allow" # TODO review occuurences +deprecated = "allow" # TODO review occuurences improper_ctypes_definitions = "deny" internal_features = "allow" # core_intrinsics and lang_items irrefutable_let_patterns = "deny" @@ -39,6 +42,7 @@ non_snake_case = "allow" # TODO review occuurences non_upper_case_globals = "allow" # TODO review occuurences unexpected_cfgs = "deny" unpredictable_function_pointer_comparisons = "deny" +unreachable_code = "allow" # TODO review occuurences unsafe_op_in_unsafe_fn = "deny" unused_imports = "deny" unused_must_use = "deny" diff --git a/src/header/grp/mod.rs b/src/header/grp/mod.rs index 1a7e486095..e2728671ae 100644 --- a/src/header/grp/mod.rs +++ b/src/header/grp/mod.rs @@ -163,13 +163,12 @@ fn parse_grp(line: String, destbuf: Option) -> Result>(); let mut buffer = buffer.split_mut(|i| *i == b'\0'); - let mut gr_gid: gid_t = 0; let strings = { let mut vec: Vec = Vec::new(); let gr_name = buffer.next().ok_or(Error::EOF)?.to_vec(); let gr_passwd = buffer.next().ok_or(Error::EOF)?.to_vec(); - gr_gid = String::from_utf8(buffer.next().ok_or(Error::EOF)?.to_vec()) + let gr_gid = String::from_utf8(buffer.next().ok_or(Error::EOF)?.to_vec()) .map_err(|err| Error::FromUtf8Error(err))? .parse::() .map_err(|err| Error::ParseIntError(err))?; diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 3f98fad564..a35e11240f 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -140,7 +140,7 @@ pub extern "C" fn alarm(seconds: c_uint) -> c_uint { // TODO setitimer is unimplemented on Redox and obsolete let timer = sys_time::itimerval { it_value: timeval { - tv_sec: seconds as time_t, + tv_sec: time_t::from(seconds), tv_usec: 0, }, ..Default::default() @@ -1003,7 +1003,7 @@ pub extern "C" fn setuid(uid: uid_t) -> c_int { #[unsafe(no_mangle)] pub extern "C" fn sleep(seconds: c_uint) -> c_uint { let rqtp = timespec { - tv_sec: seconds as time_t, + tv_sec: time_t::from(seconds), tv_nsec: 0, }; let mut rmtp = timespec { @@ -1164,8 +1164,8 @@ pub unsafe extern "C" fn unlink(path: *const c_char) -> c_int { #[unsafe(no_mangle)] pub extern "C" fn usleep(useconds: useconds_t) -> c_int { let rqtp = timespec { - tv_sec: (useconds / 1_000_000) as time_t, - tv_nsec: ((useconds % 1_000_000) * 1000) as c_long, + tv_sec: time_t::from(useconds / 1_000_000), + tv_nsec: c_long::from((useconds % 1_000_000) * 1000), }; let rmtp = ptr::null_mut(); unsafe { Sys::nanosleep(&rqtp, rmtp) } diff --git a/src/header/wctype/casecmp.rs b/src/header/wctype/casecmp.rs index 64700bdb9e..fbaf58a378 100644 --- a/src/header/wctype/casecmp.rs +++ b/src/header/wctype/casecmp.rs @@ -365,14 +365,14 @@ pub fn casemap(mut c: u32, dir: i32) -> wint_t { let x = c / 3; let y = c % 3; /* lookup entry in two-level base-6 table */ - let mut v: c_uint = tab[(tab[b as usize] as u32 * 86 + x) as usize] as c_uint; + let mut v: c_uint = c_uint::from(tab[(u32::from(tab[b as usize]) * 86 + x) as usize]); let mt: [c_uint; 3] = [2048, 342, 57]; v = (v * mt[y as usize] >> 11) % 6; /* use the bit vector out of the tables as an index into * a block-specific set of rules and decode the rule into * a type and a case-mapping delta. */ - let mut r: c_int = rules[(rulebases[b as usize] as c_uint + v) as usize]; + let mut r: c_int = rules[(c_uint::from(rulebases[b as usize]) + v) as usize]; let mut rt: c_uint = (r & 255) as c_uint; let mut rd: c_int = r >> 8; @@ -388,7 +388,7 @@ pub fn casemap(mut c: u32, dir: i32) -> wint_t { let mut xn: c_uint = (rd & 0xff) as c_uint; let mut xb: c_uint = rd as c_uint >> 8; while xn != 0 { - let attempt: c_uint = exceptions[(xb + xn / 2) as usize][0] as c_uint; + let attempt: c_uint = c_uint::from(exceptions[(xb + xn / 2) as usize][0]); if attempt == c { r = rules[exceptions[(xb + xn / 2) as usize][1] as usize]; rt = r as c_uint & 255; diff --git a/src/io/mod.rs b/src/io/mod.rs index 7f28d2b38c..e995424164 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -1383,7 +1383,7 @@ impl Read for Chain { fn read(&mut self, buf: &mut [u8]) -> Result { if !self.done_first { match self.first.read(buf)? { - 0 if buf.len() != 0 => { + 0 if !buf.is_empty() => { self.done_first = true; } n => return Ok(n), @@ -1406,7 +1406,7 @@ impl BufRead for Chain { fn fill_buf(&mut self) -> Result<&[u8]> { if !self.done_first { match self.first.fill_buf()? { - buf if buf.len() == 0 => { + buf if buf.is_empty() => { self.done_first = true; } buf => return Ok(buf), diff --git a/src/lib.rs b/src/lib.rs index cb8e7f0652..ea853da6e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,6 @@ //! Currently, Linux and Redox syscall backends are supported. #![no_std] -#![allow(warnings)] #![feature(alloc_error_handler)] #![feature(allocator_api)] #![feature(c_variadic)] diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index c70eff7385..008718a234 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -517,7 +517,7 @@ impl Pal for Sys { // Note: dev_t is c_long (i64) and __kernel_dev_t is u32; So we need to cast it // and check for overflow let k_dev: c_uint = dev as c_uint; - if k_dev as dev_t != dev { + if dev_t::from(k_dev) != dev { return Err(Errno(EINVAL)); } From 0027ba80689d6edf0acca30772f52cc2859a1b0f Mon Sep 17 00:00:00 2001 From: auronandace Date: Sun, 15 Feb 2026 21:57:16 +0000 Subject: [PATCH 2/2] revert a cast --- src/header/unistd/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index a35e11240f..142e155c5a 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -1165,7 +1165,7 @@ pub unsafe extern "C" fn unlink(path: *const c_char) -> c_int { pub extern "C" fn usleep(useconds: useconds_t) -> c_int { let rqtp = timespec { tv_sec: time_t::from(useconds / 1_000_000), - tv_nsec: c_long::from((useconds % 1_000_000) * 1000), + tv_nsec: ((useconds % 1_000_000) * 1000) as c_long, }; let rmtp = ptr::null_mut(); unsafe { Sys::nanosleep(&rqtp, rmtp) }