Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use clippy --fix to fix issues in stdlib
  • Loading branch information
terryluan12 committed Dec 29, 2025
commit a3b059965528a48bb0dc7c6c2371487944c07fa5
36 changes: 18 additions & 18 deletions crates/stdlib/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ mod array {

const fn itemsize_of_typecode(c: char) -> Option<usize> {
match c {
$($c => Some(std::mem::size_of::<$t>()),)*
$($c => Some(core::mem::size_of::<$t>()),)*
_ => None,
}
}

const fn itemsize(&self) -> usize {
match self {
$(ArrayContentType::$n(_) => std::mem::size_of::<$t>(),)*
$(ArrayContentType::$n(_) => core::mem::size_of::<$t>(),)*
}
}

Expand Down Expand Up @@ -201,10 +201,10 @@ mod array {
if v.is_empty() {
// safe because every configuration of bytes for the types we
// support are valid
let b = std::mem::ManuallyDrop::new(b);
let b = core::mem::ManuallyDrop::new(b);
let ptr = b.as_ptr() as *mut $t;
let len = b.len() / std::mem::size_of::<$t>();
let capacity = b.capacity() / std::mem::size_of::<$t>();
let len = b.len() / core::mem::size_of::<$t>();
let capacity = b.capacity() / core::mem::size_of::<$t>();
*v = unsafe { Vec::from_raw_parts(ptr, len, capacity) };
} else {
self.frombytes(&b);
Expand All @@ -220,8 +220,8 @@ mod array {
// support are valid
if b.len() > 0 {
let ptr = b.as_ptr() as *const $t;
let ptr_len = b.len() / std::mem::size_of::<$t>();
let slice = unsafe { std::slice::from_raw_parts(ptr, ptr_len) };
let ptr_len = b.len() / core::mem::size_of::<$t>();
let slice = unsafe { core::slice::from_raw_parts(ptr, ptr_len) };
v.extend_from_slice(slice);
}
})*
Expand Down Expand Up @@ -249,8 +249,8 @@ mod array {
$(ArrayContentType::$n(v) => {
// safe because we're just reading memory as bytes
let ptr = v.as_ptr() as *const u8;
let ptr_len = v.len() * std::mem::size_of::<$t>();
unsafe { std::slice::from_raw_parts(ptr, ptr_len) }
let ptr_len = v.len() * core::mem::size_of::<$t>();
unsafe { core::slice::from_raw_parts(ptr, ptr_len) }
})*
}
}
Expand All @@ -260,8 +260,8 @@ mod array {
$(ArrayContentType::$n(v) => {
// safe because we're just reading memory as bytes
let ptr = v.as_ptr() as *mut u8;
let ptr_len = v.len() * std::mem::size_of::<$t>();
unsafe { std::slice::from_raw_parts_mut(ptr, ptr_len) }
let ptr_len = v.len() * core::mem::size_of::<$t>();
unsafe { core::slice::from_raw_parts_mut(ptr, ptr_len) }
})*
}
}
Expand Down Expand Up @@ -785,18 +785,18 @@ mod array {
if item_size == 2 {
// safe because every configuration of bytes for the types we support are valid
let utf16 = unsafe {
std::slice::from_raw_parts(
core::slice::from_raw_parts(
bytes.as_ptr() as *const u16,
bytes.len() / std::mem::size_of::<u16>(),
bytes.len() / core::mem::size_of::<u16>(),
)
};
Ok(Wtf8Buf::from_wide(utf16))
} else {
// safe because every configuration of bytes for the types we support are valid
let chars = unsafe {
std::slice::from_raw_parts(
core::slice::from_raw_parts(
bytes.as_ptr() as *const u32,
bytes.len() / std::mem::size_of::<u32>(),
bytes.len() / core::mem::size_of::<u32>(),
)
};
chars
Expand Down Expand Up @@ -1516,7 +1516,7 @@ mod array {

impl MachineFormatCode {
fn from_typecode(code: char) -> Option<Self> {
use std::mem::size_of;
use core::mem::size_of;
let signed = code.is_ascii_uppercase();
let big_endian = cfg!(target_endian = "big");
let int_size = match code {
Expand Down Expand Up @@ -1590,7 +1590,7 @@ mod array {

macro_rules! chunk_to_obj {
($BYTE:ident, $TY:ty, $BIG_ENDIAN:ident) => {{
let b = <[u8; ::std::mem::size_of::<$TY>()]>::try_from($BYTE).unwrap();
let b = <[u8; ::core::mem::size_of::<$TY>()]>::try_from($BYTE).unwrap();
if $BIG_ENDIAN {
<$TY>::from_be_bytes(b)
} else {
Expand All @@ -1601,7 +1601,7 @@ mod array {
chunk_to_obj!($BYTE, $TY, $BIG_ENDIAN).to_pyobject($VM)
};
($VM:ident, $BYTE:ident, $SIGNED_TY:ty, $UNSIGNED_TY:ty, $SIGNED:ident, $BIG_ENDIAN:ident) => {{
let b = <[u8; ::std::mem::size_of::<$SIGNED_TY>()]>::try_from($BYTE).unwrap();
let b = <[u8; ::core::mem::size_of::<$SIGNED_TY>()]>::try_from($BYTE).unwrap();
match ($SIGNED, $BIG_ENDIAN) {
(false, false) => <$UNSIGNED_TY>::from_le_bytes(b).to_pyobject($VM),
(false, true) => <$UNSIGNED_TY>::from_be_bytes(b).to_pyobject($VM),
Expand Down
2 changes: 1 addition & 1 deletion crates/stdlib/src/binascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ mod decl {
}
_ => unsafe {
// quad_pos is only assigned in this match statement to constants
std::hint::unreachable_unchecked()
core::hint::unreachable_unchecked()
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/stdlib/src/cmath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod cmath {

// Constants
#[pyattr]
use std::f64::consts::{E as e, PI as pi, TAU as tau};
use core::f64::consts::{E as e, PI as pi, TAU as tau};
#[pyattr(name = "inf")]
const INF: f64 = f64::INFINITY;
#[pyattr(name = "nan")]
Expand Down Expand Up @@ -93,7 +93,7 @@ mod cmath {
z.log(
base.into_option()
.map(|base| base.re)
.unwrap_or(std::f64::consts::E),
.unwrap_or(core::f64::consts::E),
)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/stdlib/src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'a> Chunker<'a> {
pub fn advance(&mut self, consumed: usize) {
self.data1 = &self.data1[consumed..];
if self.data1.is_empty() {
self.data1 = std::mem::take(&mut self.data2);
self.data1 = core::mem::take(&mut self.data2);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions crates/stdlib/src/contextvars.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::vm::{PyRef, VirtualMachine, builtins::PyModule, class::StaticType};
use _contextvars::PyContext;
use std::cell::RefCell;
use core::cell::RefCell;

pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
let module = _contextvars::make_module(vm);
Expand Down Expand Up @@ -34,7 +34,7 @@ mod _contextvars {
use crossbeam_utils::atomic::AtomicCell;
use indexmap::IndexMap;
use std::sync::LazyLock;
use std::{
use core::{
cell::{Cell, RefCell, UnsafeCell},
sync::atomic::Ordering,
};
Expand Down Expand Up @@ -90,11 +90,11 @@ mod _contextvars {
}
}

fn borrow_vars(&self) -> impl std::ops::Deref<Target = Hamt> + '_ {
fn borrow_vars(&self) -> impl core::ops::Deref<Target = Hamt> + '_ {
self.inner.vars.hamt.borrow()
}

fn borrow_vars_mut(&self) -> impl std::ops::DerefMut<Target = Hamt> + '_ {
fn borrow_vars_mut(&self) -> impl core::ops::DerefMut<Target = Hamt> + '_ {
self.inner.vars.hamt.borrow_mut()
}

Expand Down Expand Up @@ -293,7 +293,7 @@ mod _contextvars {
#[pytraverse(skip)]
cached: AtomicCell<Option<ContextVarCache>>,
#[pytraverse(skip)]
cached_id: std::sync::atomic::AtomicUsize, // cached_tsid in CPython
cached_id: core::sync::atomic::AtomicUsize, // cached_tsid in CPython
#[pytraverse(skip)]
hash: UnsafeCell<PyHash>,
}
Expand All @@ -308,7 +308,7 @@ mod _contextvars {

impl PartialEq for ContextVar {
fn eq(&self, other: &Self) -> bool {
std::ptr::eq(self, other)
core::ptr::eq(self, other)
}
}
impl Eq for ContextVar {}
Expand Down Expand Up @@ -512,9 +512,9 @@ mod _contextvars {
}
}

impl std::hash::Hash for ContextVar {
impl core::hash::Hash for ContextVar {
#[inline]
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
unsafe { *self.hash.get() }.hash(state)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/stdlib/src/lzma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod _lzma {
use rustpython_vm::function::ArgBytesLike;
use rustpython_vm::types::Constructor;
use rustpython_vm::{Py, PyObjectRef, PyPayload, PyResult, VirtualMachine};
use std::fmt;
use alloc::fmt;
use xz2::stream::{Action, Check, Error, Filters, LzmaOptions, Status, Stream};

#[cfg(windows)]
Expand Down