Skip to content

Commit ff9be11

Browse files
committed
finish no_std clippy
1 parent 5e1fc93 commit ff9be11

File tree

14 files changed

+43
-44
lines changed

14 files changed

+43
-44
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ unsafe_op_in_unsafe_fn = "deny"
232232
elided_lifetimes_in_paths = "warn"
233233

234234
[workspace.lints.clippy]
235-
# alloc_instead_of_core = "warn"
236-
# std_instead_of_alloc = "warn"
237-
# std_instead_of_core = "warn"
235+
alloc_instead_of_core = "warn"
236+
std_instead_of_alloc = "warn"
237+
std_instead_of_core = "warn"
238238
perf = "warn"
239239
style = "warn"
240240
complexity = "warn"

crates/common/src/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn bytes_as_os_str(b: &[u8]) -> Result<&std::ffi::OsStr, Utf8Error> {
8989

9090
#[cfg(not(unix))]
9191
pub fn bytes_as_os_str(b: &[u8]) -> Result<&std::ffi::OsStr, Utf8Error> {
92-
Ok(std::str::from_utf8(b)?.as_ref())
92+
Ok(core::str::from_utf8(b)?.as_ref())
9393
}
9494

9595
#[cfg(unix)]

crates/stdlib/src/scproxy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ mod _scproxy {
9191
.find(host_key)
9292
.and_then(|v| v.downcast::<CFString>())
9393
{
94-
let h = std::borrow::Cow::<str>::from(&host);
94+
let h = alloc::borrow::Cow::<str>::from(&host);
9595
let v = if let Some(port) = proxy_dict
9696
.find(port_key)
9797
.and_then(|v| v.downcast::<CFNumber>())

crates/stdlib/src/socket.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ mod _socket {
19361936
flags: OptionalArg<i32>,
19371937
vm: &VirtualMachine,
19381938
) -> PyResult<PyTupleRef> {
1939-
use std::mem::MaybeUninit;
1939+
use core::mem::MaybeUninit;
19401940

19411941
if bufsize < 0 {
19421942
return Err(vm.new_value_error("negative buffer size in recvmsg".to_owned()));
@@ -1955,7 +1955,7 @@ mod _socket {
19551955
// Allocate buffers
19561956
let mut data_buf: Vec<MaybeUninit<u8>> = vec![MaybeUninit::uninit(); bufsize];
19571957
let mut anc_buf: Vec<MaybeUninit<u8>> = vec![MaybeUninit::uninit(); ancbufsize];
1958-
let mut addr_storage: libc::sockaddr_storage = unsafe { std::mem::zeroed() };
1958+
let mut addr_storage: libc::sockaddr_storage = unsafe { core::mem::zeroed() };
19591959

19601960
// Set up iovec
19611961
let mut iov = [libc::iovec {
@@ -1964,9 +1964,9 @@ mod _socket {
19641964
}];
19651965

19661966
// Set up msghdr
1967-
let mut msg: libc::msghdr = unsafe { std::mem::zeroed() };
1967+
let mut msg: libc::msghdr = unsafe { core::mem::zeroed() };
19681968
msg.msg_name = (&mut addr_storage as *mut libc::sockaddr_storage).cast();
1969-
msg.msg_namelen = std::mem::size_of::<libc::sockaddr_storage>() as libc::socklen_t;
1969+
msg.msg_namelen = core::mem::size_of::<libc::sockaddr_storage>() as libc::socklen_t;
19701970
msg.msg_iov = iov.as_mut_ptr();
19711971
msg.msg_iovlen = 1;
19721972
if ancbufsize > 0 {
@@ -1990,7 +1990,7 @@ mod _socket {
19901990
// Build data bytes
19911991
let data = unsafe {
19921992
data_buf.set_len(n);
1993-
std::mem::transmute::<Vec<MaybeUninit<u8>>, Vec<u8>>(data_buf)
1993+
core::mem::transmute::<Vec<MaybeUninit<u8>>, Vec<u8>>(data_buf)
19941994
};
19951995

19961996
// Build ancdata list
@@ -1999,7 +1999,7 @@ mod _socket {
19991999
// Build address tuple
20002000
let address = if msg.msg_namelen > 0 {
20012001
let storage: socket2::SockAddrStorage =
2002-
unsafe { std::mem::transmute(addr_storage) };
2002+
unsafe { core::mem::transmute(addr_storage) };
20032003
let addr = unsafe { socket2::SockAddr::new(storage, msg.msg_namelen) };
20042004
get_addr_tuple(&addr, vm)
20052005
} else {
@@ -2034,7 +2034,7 @@ mod _socket {
20342034
let available = ctrl_end as usize - data_ptr as usize;
20352035
let data_len = data_len_from_cmsg.min(available);
20362036

2037-
let data = unsafe { std::slice::from_raw_parts(data_ptr, data_len) };
2037+
let data = unsafe { core::slice::from_raw_parts(data_ptr, data_len) };
20382038

20392039
let tuple = vm.ctx.new_tuple(vec![
20402040
vm.ctx.new_int(cmsg_ref.cmsg_level).into(),
@@ -2820,13 +2820,11 @@ mod _socket {
28202820
let host = host_encoded.as_deref();
28212821

28222822
// Encode port using UTF-8
2823-
let port: Option<std::borrow::Cow<'_, str>> = match opts.port.as_ref() {
2824-
Some(Either::A(s)) => {
2825-
Some(std::borrow::Cow::Borrowed(s.to_str().ok_or_else(|| {
2826-
vm.new_unicode_encode_error("surrogates not allowed".to_owned())
2827-
})?))
2828-
}
2829-
Some(Either::B(i)) => Some(std::borrow::Cow::Owned(i.to_string())),
2823+
let port: Option<alloc::borrow::Cow<'_, str>> = match opts.port.as_ref() {
2824+
Some(Either::A(s)) => Some(alloc::borrow::Cow::Borrowed(s.to_str().ok_or_else(
2825+
|| vm.new_unicode_encode_error("surrogates not allowed".to_owned()),
2826+
)?)),
2827+
Some(Either::B(i)) => Some(alloc::borrow::Cow::Owned(i.to_string())),
28302828
None => None,
28312829
};
28322830
let port = port.as_ref().map(|p| p.as_ref());

crates/vm/src/stdlib/ctypes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ pub(crate) mod _ctypes {
11801180
path: Option<PyObjectRef>,
11811181
vm: &VirtualMachine,
11821182
) -> PyResult<bool> {
1183-
use std::ffi::CString;
1183+
use alloc::ffi::CString;
11841184

11851185
let path = match path {
11861186
Some(p) if !vm.is_none(&p) => p,

crates/vm/src/stdlib/ctypes/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::{
1212
protocol::{BufferDescriptor, PyBuffer, PyNumberMethods, PySequenceMethods},
1313
types::{AsBuffer, AsNumber, AsSequence, Constructor, Initializer},
1414
};
15+
use alloc::borrow::Cow;
1516
use num_traits::{Signed, ToPrimitive};
16-
use std::borrow::Cow;
1717

1818
/// Get itemsize from a PEP 3118 format string
1919
/// Extracts the type code (last char after endianness prefix) and returns its size
@@ -890,7 +890,7 @@ impl PyCArray {
890890
// Python's from_buffer requires writable buffer, so this is safe.
891891
let ptr = slice.as_ptr() as *mut u8;
892892
let len = slice.len();
893-
let owned_slice = unsafe { std::slice::from_raw_parts_mut(ptr, len) };
893+
let owned_slice = unsafe { core::slice::from_raw_parts_mut(ptr, len) };
894894
Self::write_element_to_buffer(
895895
owned_slice,
896896
final_offset,

crates/vm/src/stdlib/ctypes/simple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ impl PyCSimple {
13041304
let ptr = slice.as_ptr() as *mut u8;
13051305
let len = slice.len().min(buffer_bytes.len());
13061306
unsafe {
1307-
std::ptr::copy_nonoverlapping(buffer_bytes.as_ptr(), ptr, len);
1307+
core::ptr::copy_nonoverlapping(buffer_bytes.as_ptr(), ptr, len);
13081308
}
13091309
}
13101310
Cow::Owned(vec) => {

crates/vm/src/stdlib/os.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,16 +1747,16 @@ pub(super) mod _os {
17471747
// We extract raw bytes and interpret as a native-endian integer.
17481748
// Note: The value may differ across architectures due to endianness.
17491749
let f_fsid = {
1750-
let ptr = std::ptr::addr_of!(st.f_fsid) as *const u8;
1751-
let size = std::mem::size_of_val(&st.f_fsid);
1750+
let ptr = core::ptr::addr_of!(st.f_fsid) as *const u8;
1751+
let size = core::mem::size_of_val(&st.f_fsid);
17521752
if size >= 8 {
1753-
let bytes = unsafe { std::slice::from_raw_parts(ptr, 8) };
1753+
let bytes = unsafe { core::slice::from_raw_parts(ptr, 8) };
17541754
u64::from_ne_bytes([
17551755
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6],
17561756
bytes[7],
17571757
]) as libc::c_ulong
17581758
} else if size >= 4 {
1759-
let bytes = unsafe { std::slice::from_raw_parts(ptr, 4) };
1759+
let bytes = unsafe { core::slice::from_raw_parts(ptr, 4) };
17601760
u32::from_ne_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]) as libc::c_ulong
17611761
} else {
17621762
0
@@ -1784,7 +1784,7 @@ pub(super) mod _os {
17841784
#[pyfunction]
17851785
#[pyfunction(name = "fstatvfs")]
17861786
fn statvfs(path: OsPathOrFd<'_>, vm: &VirtualMachine) -> PyResult {
1787-
let mut st: libc::statvfs = unsafe { std::mem::zeroed() };
1787+
let mut st: libc::statvfs = unsafe { core::mem::zeroed() };
17881788
let ret = match &path {
17891789
OsPathOrFd::Path(p) => {
17901790
let cpath = p.clone().into_cstring(vm)?;

crates/vm/src/stdlib/posix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,9 @@ pub mod module {
360360

361361
#[cfg(any(target_os = "macos", target_os = "ios"))]
362362
fn getgroups_impl() -> nix::Result<Vec<Gid>> {
363+
use core::ptr;
363364
use libc::{c_int, gid_t};
364365
use nix::errno::Errno;
365-
use std::ptr;
366366
let ret = unsafe { libc::getgroups(0, ptr::null_mut()) };
367367
let mut groups = Vec::<Gid>::with_capacity(Errno::result(ret)? as usize);
368368
let ret = unsafe {
@@ -1825,7 +1825,7 @@ pub mod module {
18251825
#[cfg(target_os = "macos")]
18261826
#[pyfunction]
18271827
fn _fcopyfile(in_fd: i32, out_fd: i32, flags: i32, vm: &VirtualMachine) -> PyResult<()> {
1828-
let ret = unsafe { fcopyfile(in_fd, out_fd, std::ptr::null_mut(), flags as u32) };
1828+
let ret = unsafe { fcopyfile(in_fd, out_fd, core::ptr::null_mut(), flags as u32) };
18291829
if ret < 0 {
18301830
Err(vm.new_last_errno_error())
18311831
} else {

crates/vm/src/stdlib/thread.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub(crate) mod _thread {
192192
#[derive(PyPayload)]
193193
struct RLock {
194194
mu: RawRMutex,
195-
count: std::sync::atomic::AtomicUsize,
195+
count: core::sync::atomic::AtomicUsize,
196196
}
197197

198198
impl fmt::Debug for RLock {
@@ -207,7 +207,7 @@ pub(crate) mod _thread {
207207
fn slot_new(cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult {
208208
Self {
209209
mu: RawRMutex::INIT,
210-
count: std::sync::atomic::AtomicUsize::new(0),
210+
count: core::sync::atomic::AtomicUsize::new(0),
211211
}
212212
.into_ref_with_type(vm, cls)
213213
.map(Into::into)
@@ -220,7 +220,7 @@ pub(crate) mod _thread {
220220
let result = acquire_lock_impl!(&self.mu, args, vm)?;
221221
if result {
222222
self.count
223-
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
223+
.fetch_add(1, core::sync::atomic::Ordering::Relaxed);
224224
}
225225
Ok(result)
226226
}
@@ -231,11 +231,11 @@ pub(crate) mod _thread {
231231
return Err(vm.new_runtime_error("release unlocked lock"));
232232
}
233233
debug_assert!(
234-
self.count.load(std::sync::atomic::Ordering::Relaxed) > 0,
234+
self.count.load(core::sync::atomic::Ordering::Relaxed) > 0,
235235
"RLock count underflow"
236236
);
237237
self.count
238-
.fetch_sub(1, std::sync::atomic::Ordering::Relaxed);
238+
.fetch_sub(1, core::sync::atomic::Ordering::Relaxed);
239239
unsafe { self.mu.unlock() };
240240
Ok(())
241241
}
@@ -247,7 +247,7 @@ pub(crate) mod _thread {
247247
self.mu.unlock();
248248
};
249249
}
250-
self.count.store(0, std::sync::atomic::Ordering::Relaxed);
250+
self.count.store(0, core::sync::atomic::Ordering::Relaxed);
251251
let new_mut = RawRMutex::INIT;
252252

253253
let old_mutex: AtomicCell<&RawRMutex> = AtomicCell::new(&self.mu);
@@ -264,7 +264,7 @@ pub(crate) mod _thread {
264264
#[pymethod]
265265
fn _recursion_count(&self) -> usize {
266266
if self.mu.is_owned_by_current_thread() {
267-
self.count.load(std::sync::atomic::Ordering::Relaxed)
267+
self.count.load(core::sync::atomic::Ordering::Relaxed)
268268
} else {
269269
0
270270
}

0 commit comments

Comments
 (0)