add unused-unsafe lint

This commit is contained in:
auronandace
2026-02-08 15:39:48 +00:00
parent 1ec204d702
commit c3f3e051e1
11 changed files with 47 additions and 66 deletions
+4
View File
@@ -44,6 +44,8 @@ non_camel_case_types = "allow"
unpredictable_function_pointer_comparisons = "deny"
unsafe_op_in_unsafe_fn = "deny"
unused_mut = "deny"
unused_unsafe = "deny"
unused_variables = "allow" # TODO review occurrences (too many for now)
[lints.rust]
dangling_pointers_from_temporaries = "deny"
@@ -52,6 +54,8 @@ non_camel_case_types = "allow"
unpredictable_function_pointer_comparisons = "deny"
unsafe_op_in_unsafe_fn = "deny"
unused_mut = "deny"
unused_unsafe = "deny"
unused_variables = "allow" # TODO review occurrences (too many for now)
[build-dependencies]
cc = "1"
+2 -5
View File
@@ -11,9 +11,8 @@ use crate::{
error::{Errno, ResultExt, ResultExtPtrMut},
fs::File,
header::{
errno::{self, EINVAL, EIO, ENOMEM, ENOTDIR},
errno::{EINVAL, EIO, ENOMEM, ENOTDIR},
fcntl, stdlib, string, sys_stat,
unistd::{SEEK_CUR, SEEK_SET},
},
out::Out,
platform::{
@@ -52,9 +51,7 @@ impl DIR {
}
pub fn from_fd(fd: c_int) -> Result<Box<Self>, Errno> {
let mut stat = sys_stat::stat::default();
unsafe {
Sys::fstat(fd, Out::from_mut(&mut stat))?;
}
Sys::fstat(fd, Out::from_mut(&mut stat))?;
if (stat.st_mode & sys_stat::S_IFMT) != sys_stat::S_IFDIR {
return Err(Errno(ENOTDIR));
}
+2 -2
View File
@@ -30,7 +30,7 @@ pub extern "C" fn __errno_location() -> *mut c_int {
/// The `program_invocation_name` variable is a GNU extension.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn __program_invocation_name() -> *mut *mut c_char {
unsafe { &raw mut platform::program_invocation_name }
&raw mut platform::program_invocation_name
}
/// Get the directory-less name used to invoke the program.
@@ -41,7 +41,7 @@ pub unsafe extern "C" fn __program_invocation_name() -> *mut *mut c_char {
/// The `program_invocation_short_name` variable is a GNU extension.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn __program_invocation_short_name() -> *mut *mut c_char {
unsafe { &raw mut platform::program_invocation_short_name }
&raw mut platform::program_invocation_short_name
}
pub const EPERM: c_int = 1; /* Operation not permitted */
+18 -22
View File
@@ -39,17 +39,15 @@ pub unsafe extern "C" fn strtoimax(
endptr: *mut *mut c_char,
base: c_int,
) -> intmax_t {
unsafe {
strto_impl!(
intmax_t,
false,
intmax_t::max_value(),
intmax_t::min_value(),
s,
endptr,
base
)
}
strto_impl!(
intmax_t,
false,
intmax_t::max_value(),
intmax_t::min_value(),
s,
endptr,
base
)
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoimax.html>.
@@ -59,17 +57,15 @@ pub unsafe extern "C" fn strtoumax(
endptr: *mut *mut c_char,
base: c_int,
) -> uintmax_t {
unsafe {
strto_impl!(
uintmax_t,
false,
uintmax_t::max_value(),
uintmax_t::min_value(),
s,
endptr,
base
)
}
strto_impl!(
uintmax_t,
false,
uintmax_t::max_value(),
uintmax_t::min_value(),
s,
endptr,
base
)
}
// wcstoimax(), wcstoumax() currently defined in header::wchar?
+9 -17
View File
@@ -1,8 +1,4 @@
use alloc::{
boxed::Box,
string::{String, ToString},
vec::{IntoIter, Vec},
};
use alloc::{boxed::Box, string::ToString, vec::Vec};
use core::mem;
use crate::{
@@ -43,12 +39,10 @@ pub fn lookup_host(host: &str) -> Result<LookupHost, c_int> {
if let Some(dns_addr) = parse_ipv4_string(&dns_string) {
let mut timespec = timespec::default();
unsafe {
Sys::clock_gettime(
time::constants::CLOCK_REALTIME,
Out::from_mut(&mut timespec),
);
}
Sys::clock_gettime(
time::constants::CLOCK_REALTIME,
Out::from_mut(&mut timespec),
);
let tid = (timespec.tv_nsec >> 16) as u16;
let packet = Dns {
@@ -147,12 +141,10 @@ pub fn lookup_addr(addr: in_addr) -> Result<Vec<Vec<u8>>, c_int> {
);
let mut timespec = timespec::default();
unsafe {
Sys::clock_gettime(
time::constants::CLOCK_REALTIME,
Out::from_mut(&mut timespec),
)
};
Sys::clock_gettime(
time::constants::CLOCK_REALTIME,
Out::from_mut(&mut timespec),
);
let tid = (timespec.tv_nsec >> 16) as u16;
let packet = Dns {
+1 -1
View File
@@ -159,7 +159,7 @@ pub unsafe extern "C" fn pthread_attr_setschedparam(
param: *const sched_param,
) -> c_int {
unsafe {
(*attr.cast::<RlctAttr>()).param = unsafe { param.read() };
(*attr.cast::<RlctAttr>()).param = param.read();
}
0
}
+1 -2
View File
@@ -35,7 +35,6 @@ use crate::{
self, ERRNO, Pal, Sys, WriteByte,
types::{c_char, c_int, c_long, c_uint, c_ulonglong, c_void, off_t, size_t},
},
sync::Mutex,
};
pub use self::constants::*;
@@ -420,7 +419,7 @@ pub unsafe extern "C" fn fflush(stream: *mut FILE) -> c_int {
return EOF;
}
} else {
let mut stream = unsafe { unsafe { (*stream).lock() } };
let mut stream = unsafe { (*stream).lock() };
if stream.flush().is_err() {
return EOF;
}
+1 -1
View File
@@ -1102,7 +1102,7 @@ pub unsafe extern "C" fn rand() -> c_int {
None => {
let mut rng = XorShiftRng::from_seed([1; 16]);
let ret = rng_sampler().sample(&mut rng);
unsafe { RNG = Some(rng) };
RNG = Some(rng);
ret
}
}
+4 -8
View File
@@ -2,17 +2,13 @@
//
// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/strptime.html>.
use crate::{
header::{string::strlen, time::tm},
platform::types::size_t,
};
use alloc::{string::String, vec::Vec};
use crate::header::time::tm;
use alloc::string::String;
use core::{
ffi::{CStr, c_char, c_int, c_void},
mem::MaybeUninit,
ptr,
ptr::NonNull,
slice, str,
str,
};
/// For convenience, we define some helper constants for the C-locale.
@@ -153,7 +149,7 @@ pub unsafe extern "C" fn strptime(
'd' | 'e' => {
// parse a 2-digit day (with or without leading zero)
let (val, len) = match parse_int(&input_str[index_in_input..], 2, false) {
Some(v) => unsafe { v },
Some(v) => v,
None => return ptr::null_mut(),
};
unsafe {
+1 -1
View File
@@ -52,7 +52,7 @@ pub unsafe fn mbrtowc(pwc: *mut wchar_t, s: *const c_char, n: usize, ps: *mut mb
}
if size == 0 {
platform::ERRNO.set(errno::EILSEQ);
return unsafe { -1isize as usize };
return -1isize as usize;
}
let slice = unsafe { slice::from_raw_parts(s as *const u8, size) };
+4 -7
View File
@@ -362,18 +362,15 @@ unsafe fn inner_scanf(
}
}
let mut ptr: Option<*mut $type> = if ignore {
None
} else {
Some(unsafe { ap.arg() })
};
let mut ptr: Option<*mut $type> =
if ignore { None } else { Some(ap.arg()) };
while width.map(|w| w > 0).unwrap_or(true)
&& !(wc_as_char!(wchar)).is_whitespace()
{
if let Some(ref mut ptr) = ptr {
unsafe { **ptr = wchar as $type };
*ptr = unsafe { ptr.offset(1) };
**ptr = wchar as $type;
*ptr = ptr.offset(1);
}
width = width.map(|w| w - 1);
if width.map(|w| w > 0).unwrap_or(true) && !read!() {