add unused_mut lint

This commit is contained in:
auronandace
2026-02-08 09:00:14 +00:00
parent a935094d2d
commit 64f18ca89a
18 changed files with 48 additions and 76 deletions
+2
View File
@@ -43,6 +43,7 @@ irrefutable_let_patterns = "deny"
non_camel_case_types = "allow"
unpredictable_function_pointer_comparisons = "deny"
unsafe_op_in_unsafe_fn = "deny"
unused_mut = "deny"
[lints.rust]
dangling_pointers_from_temporaries = "deny"
@@ -50,6 +51,7 @@ irrefutable_let_patterns = "deny"
non_camel_case_types = "allow"
unpredictable_function_pointer_comparisons = "deny"
unsafe_op_in_unsafe_fn = "deny"
unused_mut = "deny"
[build-dependencies]
cc = "1"
+4 -4
View File
@@ -9,10 +9,10 @@ use alloc::{boxed::Box, vec::Vec};
use crate::{
c_str::{CStr, CString},
header::{
dirent::{DIR, closedir, opendir, readdir},
dirent::{closedir, opendir, readdir},
errno::*,
fnmatch::{FNM_NOESCAPE, FNM_PERIOD, fnmatch},
sys_stat::{S_IFDIR, S_IFLNK, S_IFMT, stat},
sys_stat::{S_IFDIR, S_IFMT, stat},
},
platform::{
self,
@@ -200,7 +200,7 @@ fn list_dir(
} else {
path
};
let mut dir = unsafe { opendir(open_path.as_ptr()) };
let dir = unsafe { opendir(open_path.as_ptr()) };
if dir.is_null() {
let new_errno = platform::ERRNO.get();
@@ -295,7 +295,7 @@ fn inner_glob(
};
// Get the next section of the glob expression (up to non-escaped '/')
let mut glob_iter = glob_expr.to_bytes();
let glob_iter = glob_expr.to_bytes();
let mut in_bracket = false;
let mut escaped = false;
let mut glob_consumed = 0;
+5 -9
View File
@@ -4,14 +4,12 @@
use core::{
cell::SyncUnsafeCell,
convert::{TryFrom, TryInto},
convert::TryInto,
mem::{self, MaybeUninit},
num::ParseIntError,
ops::{Deref, DerefMut},
pin::Pin,
primitive::str,
ptr, slice,
str::Matches,
};
use alloc::{
@@ -20,14 +18,12 @@ use alloc::{
};
use crate::{
c_str::CStr,
fs::File,
header::{errno, fcntl, limits, string::strlen, unistd},
io,
io::{BufReader, Lines, prelude::*},
platform,
platform::types::{c_char, c_int, c_void, gid_t, size_t},
sync::Mutex,
};
use super::{errno::*, string::strncmp};
@@ -158,7 +154,7 @@ fn split(buf: &mut [u8]) -> Option<group> {
}
fn parse_grp(line: String, destbuf: Option<DestBuffer>) -> Result<OwnedGrp, Error> {
let mut buffer = line.to_owned().into_bytes();
let buffer = line.to_owned().into_bytes();
let mut buffer = buffer
.into_iter()
@@ -385,7 +381,7 @@ pub unsafe extern "C" fn getgrnam_r(
for line in BufReader::new(db).lines() {
let Ok(line) = line else { return EINVAL };
let Ok(mut grp) = parse_grp(
let Ok(grp) = parse_grp(
line,
Some(DestBuffer {
ptr: buffer as *mut u8,
@@ -461,7 +457,7 @@ pub unsafe extern "C" fn endgrent() {
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/endgrent.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn setgrent() {
let mut line_reader = unsafe { &mut *LINE_READER.get() };
let line_reader = unsafe { &mut *LINE_READER.get() };
let Ok(db) = File::open(GROUP_FILE.into(), fcntl::O_RDONLY) else {
return;
};
@@ -479,7 +475,7 @@ pub unsafe extern "C" fn getgrouplist(
groups: *mut gid_t,
ngroups: *mut c_int,
) -> c_int {
let mut grps = unsafe {
let grps = unsafe {
slice::from_raw_parts_mut(groups.cast::<MaybeUninit<gid_t>>(), ngroups.read() as usize)
};
+2 -3
View File
@@ -11,8 +11,7 @@ use crate::{
fs::File,
header::{errno, fcntl},
io::Read,
platform::types::{c_char, c_int, c_void},
sync::Once,
platform::types::{c_char, c_int},
};
// Can't use &str because of the mutability
@@ -58,7 +57,7 @@ pub unsafe extern "C" fn setlocale(category: c_int, locale: *const c_char) -> *m
let new_global = GlobalLocaleData::new();
unsafe { GLOBAL_LOCALE = Box::into_raw(new_global) };
};
let Some(mut global) = (unsafe { GLOBAL_LOCALE.as_mut() }) else {
let Some(global) = (unsafe { GLOBAL_LOCALE.as_mut() }) else {
return ptr::null_mut();
};
+10 -15
View File
@@ -372,7 +372,7 @@ pub unsafe extern "C" fn gethostbyname(name: *const c_char) -> *mut hostent {
}
}
let mut host = match lookup_host(name_str) {
let host = match lookup_host(name_str) {
Ok(lookuphost) => lookuphost,
Err(e) => {
H_ERRNO.set(NO_RECOVERY);
@@ -403,7 +403,7 @@ pub unsafe extern "C" fn gethostbyname(name: *const c_char) -> *mut hostent {
unsafe {
HOST_ENTRY = hostent {
h_name: unsafe { HOST_NAME.unsafe_mut().as_mut().unwrap().as_mut_ptr() } as *mut c_char,
h_name: HOST_NAME.unsafe_mut().as_mut().unwrap().as_mut_ptr() as *mut c_char,
h_aliases: host_aliases.as_mut_slice().as_mut_ptr(),
h_addrtype: AF_INET,
h_length: 4,
@@ -490,10 +490,7 @@ pub unsafe extern "C" fn getnetent() -> *mut netent {
unsafe {
NET_ENTRY = netent {
n_name: unsafe { NET_NAME.unsafe_mut() }
.as_mut()
.unwrap()
.as_mut_ptr() as *mut c_char,
n_name: NET_NAME.unsafe_mut().as_mut().unwrap().as_mut_ptr() as *mut c_char,
n_aliases: net_aliases.as_mut_slice().as_mut_ptr(),
n_addrtype: AF_INET,
n_net: NET_ADDR.unwrap() as c_ulong,
@@ -606,16 +603,14 @@ pub unsafe extern "C" fn getprotoent() -> *mut protoent {
unsafe {
PROTO_ENTRY = protoent {
p_name: unsafe {
PROTO_NAME
.unsafe_mut()
.as_mut()
.unwrap()
.as_mut_slice()
.as_mut_ptr()
} as *mut c_char,
p_name: PROTO_NAME
.unsafe_mut()
.as_mut()
.unwrap()
.as_mut_slice()
.as_mut_ptr() as *mut c_char,
p_aliases: proto_aliases.as_mut_slice().as_mut_ptr() as *mut *mut c_char,
p_proto: unsafe { PROTO_NUM }.unwrap(),
p_proto: PROTO_NUM.unwrap(),
}
};
if unsafe { PROTO_STAYOPEN } == 0 {
+3 -4
View File
@@ -5,7 +5,6 @@
use core::{mem, ptr, slice};
use crate::{
error::ResultExt,
fs::File,
header::{
errno::EBADF,
@@ -68,7 +67,7 @@ pub unsafe fn poll_epoll(fds: &mut [pollfd], timeout: c_int, sigmask: *const sig
let mut closed = 0;
for i in 0..fds.len() {
let mut pfd = &mut fds[i];
let pfd = &mut fds[i];
pfd.revents = 0;
@@ -145,7 +144,7 @@ pub unsafe extern "C" fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: c_int) ->
trace_expr!(
unsafe {
poll_epoll(
unsafe { slice::from_raw_parts_mut(fds, nfds as usize) },
slice::from_raw_parts_mut(fds, nfds as usize),
timeout,
ptr::null_mut(),
)
@@ -178,7 +177,7 @@ pub unsafe extern "C" fn ppoll(
trace_expr!(
unsafe {
poll_epoll(
unsafe { slice::from_raw_parts_mut(fds, nfds as usize) },
slice::from_raw_parts_mut(fds, nfds as usize),
timeout,
sigmask,
)
+2 -2
View File
@@ -7,7 +7,7 @@ use crate::{
platform::types::{c_char, c_int, c_void, size_t},
};
use alloc::{borrow::Cow, boxed::Box};
use core::{mem, ptr, slice};
use core::{ptr, slice};
use posix_regex::{PosixRegex, PosixRegexBuilder, compile::Error as CompileError, tree::Tree};
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/regex.h.html>.
@@ -63,7 +63,7 @@ pub unsafe extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags:
.compile_tokens();
match res {
Ok(mut branches) => {
Ok(branches) => {
let re_nsub = PosixRegex::new(Cow::Borrowed(&branches)).count_groups();
unsafe {
*out = regex_t {
+2 -4
View File
@@ -1,7 +1,5 @@
use core::{
cell::SyncUnsafeCell,
convert::TryInto,
mem,
ops::{Deref, DerefMut},
pin::Pin,
ptr,
@@ -13,7 +11,7 @@ use alloc::{boxed::Box, string::String, vec::Vec};
use crate::{
c_str::CStr,
fs::File,
header::{errno, fcntl, string::strlen},
header::fcntl,
io::{BufReader, Lines, prelude::*},
platform,
platform::types::{c_char, c_int, c_long, c_ulong, size_t},
@@ -237,7 +235,7 @@ pub unsafe extern "C" fn getspnam_r(
#[unsafe(no_mangle)]
pub unsafe extern "C" fn setspent() {
let mut line_reader = unsafe { &mut *LINE_READER.get() };
let line_reader = unsafe { &mut *LINE_READER.get() };
if let Ok(db) = File::open(SHADOW_FILE.into(), fcntl::O_RDONLY) {
*line_reader = Some(BufReader::new(db).lines());
}
+2 -8
View File
@@ -1,13 +1,7 @@
use super::{BUFSIZ, Buffer, FILE, constants};
use core::{cell::UnsafeCell, ptr};
use crate::{
fs::File,
header::pthread,
io::LineWriter,
platform::types::c_int,
sync::{Mutex, Once},
};
use crate::{fs::File, header::pthread, io::LineWriter, platform::types::c_int, sync::Once};
use alloc::{boxed::Box, vec::Vec};
// TODO: Change FILE to allow const fn initialization?
@@ -17,7 +11,7 @@ impl GlobalFile {
fn new(file: c_int, flags: c_int) -> Self {
let file = File::new(file);
let writer = Box::new(LineWriter::new(unsafe { file.get_ref() }));
let mut mutex_attr = pthread::RlctMutexAttr {
let mutex_attr = pthread::RlctMutexAttr {
ty: pthread::PTHREAD_MUTEX_RECURSIVE,
..Default::default()
};
+3 -7
View File
@@ -9,7 +9,7 @@ use crate::{
error::Errno,
fs::File,
header::{
errno::{self, EINVAL},
errno::EINVAL,
fcntl::{
F_GETFL, F_SETFD, F_SETFL, FD_CLOEXEC, O_APPEND, O_CLOEXEC, O_CREAT, O_EXCL, O_RDONLY,
O_RDWR, O_TRUNC, O_WRONLY, fcntl,
@@ -17,11 +17,7 @@ use crate::{
pthread,
},
io::BufWriter,
platform::{
self,
types::{c_int, c_ulonglong},
},
sync::Mutex,
platform::types::{c_int, c_ulonglong},
};
use alloc::vec::Vec;
@@ -79,7 +75,7 @@ pub fn _fdopen(fd: c_int, mode: CStr) -> Result<Box<FILE>, Errno> {
let file = File::new(fd);
let writer = Box::new(BufWriter::new(unsafe { file.get_ref() }));
let mut mutex_attr = pthread::RlctMutexAttr {
let mutex_attr = pthread::RlctMutexAttr {
ty: pthread::PTHREAD_MUTEX_RECURSIVE,
..Default::default()
};
+2 -6
View File
@@ -2,11 +2,7 @@
//!
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/string.h.html>.
use core::{
iter::once,
mem::{self, MaybeUninit},
ptr, slice, usize,
};
use core::{iter::once, mem, ptr, slice, usize};
use cbitset::BitSet256;
@@ -257,7 +253,7 @@ pub unsafe extern "C" fn strcat(s1: *mut c_char, s2: *const c_char) -> *mut c_ch
/// containing at least one nul value. The pointed-to buffer must not be
/// modified for the duration of the call.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn strchr(mut s: *const c_char, c: c_int) -> *mut c_char {
pub unsafe extern "C" fn strchr(s: *const c_char, c: c_int) -> *mut c_char {
let c_as_c_char = c as c_char;
// We iterate over non-mut references and thus need to coerce the
+1 -2
View File
@@ -151,8 +151,7 @@ pub unsafe extern "C" fn strncasecmp(s1: *const c_char, s2: *const c_char, n: si
/// Given two zipped `&c_char` iterators, either find the first comparison != 0, or return 0.
fn inner_casecmp<'a>(iterator: impl Iterator<Item = (&'a c_char, &'a c_char)>) -> c_int {
let mut cmp_iter =
iterator.map(|(&c1, &c2)| ctype::tolower(c1.into()) - ctype::tolower(c2.into()));
let cmp_iter = iterator.map(|(&c1, &c2)| ctype::tolower(c1.into()) - ctype::tolower(c2.into()));
let mut skip_iter = cmp_iter.skip_while(|&cmp| cmp == 0);
skip_iter.next().or(Some(0)).unwrap()
}
+3 -7
View File
@@ -1,8 +1,4 @@
use alloc::{
borrow::ToOwned,
string::{String, ToString},
vec::Vec,
};
use alloc::{borrow::ToOwned, string::String};
use core::{ffi::VaList, ptr::null_mut};
use crate::{
@@ -21,7 +17,7 @@ use crate::{
sync::Mutex,
};
use bitflags::{Flags, bitflags};
use bitflags::bitflags;
use chrono::{DateTime, Utc};
use super::{
@@ -53,7 +49,7 @@ impl<L: LogSink> LogParams<L> {
}
}
pub fn write_log(&mut self, priority: Priority, message: CStr<'_>, mut ap: VaList) {
pub fn write_log(&mut self, priority: Priority, message: CStr<'_>, ap: VaList) {
if message.is_empty() {
return;
}
+1 -1
View File
@@ -119,7 +119,7 @@ pub unsafe extern "C" fn openlog(ident: *const c_char, opt: c_int, facility: c_i
///
/// Non-POSIX, 4.3BSD-Reno.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn vsyslog(priority: c_int, message: *const c_char, mut ap: VaList) {
pub unsafe extern "C" fn vsyslog(priority: c_int, message: *const c_char, ap: VaList) {
let Some(message) = (unsafe { CStr::from_nullable_ptr(message) }) else {
return;
};
+2 -2
View File
@@ -147,7 +147,7 @@ pub unsafe extern "C" fn access(path: *const c_char, mode: c_int) -> c_int {
#[unsafe(no_mangle)]
pub extern "C" fn alarm(seconds: c_uint) -> c_uint {
// TODO setitimer is unimplemented on Redox and obsolete
let mut timer = sys_time::itimerval {
let timer = sys_time::itimerval {
it_value: timeval {
tv_sec: seconds as time_t,
tv_usec: 0,
@@ -1035,7 +1035,7 @@ pub unsafe extern "C" fn swab(src: *const c_void, dest: *mut c_void, nbytes: ssi
}
let number_of_swaps = nbytes / 2;
let mut offset = 0;
for i in 0..number_of_swaps {
for _ in 0..number_of_swaps {
unsafe {
src.offset(offset).copy_to(dest.offset(offset + 1), 1);
src.offset(offset + 1).copy_to(dest.offset(offset), 1);
+1 -1
View File
@@ -844,7 +844,7 @@ impl Pal for Sys {
timerid: timer_t,
flags: c_int,
value: &itimerspec,
mut ovalue: Option<Out<itimerspec>>,
ovalue: Option<Out<itimerspec>>,
) -> Result<()> {
e_raw(unsafe {
syscall!(
+2
View File
@@ -19,6 +19,7 @@ use crate::{
use crate::sync::{Mutex, waitval::Waitval};
/// Called only by the main thread, as part of relibc_start.
#[allow(unused_mut)]
pub unsafe fn init() {
let mut thread = Pthread {
waitval: Waitval::new(),
@@ -102,6 +103,7 @@ impl Drop for MmapGuard {
}
}
#[allow(unused_mut)]
pub(crate) unsafe fn create(
attrs: Option<&header::RlctAttr>,
start_routine: extern "C" fn(arg: *mut c_void) -> *mut c_void,
+1 -1
View File
@@ -76,7 +76,7 @@ impl RlctMutex {
fn lock_inner(&self, deadline: Option<&timespec>) -> Result<(), Errno> {
let this_thread = os_tid_invalid_after_fork();
let mut spins_left = SPIN_COUNT;
//let mut spins_left = SPIN_COUNT;
loop {
let result = self.inner.compare_exchange_weak(