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
* Used clippy --fix to fix issues in common
  • Loading branch information
terryluan12 committed Dec 29, 2025
commit abcc9faa0f80171cd773d964f1e60bffc43dd745
2 changes: 1 addition & 1 deletion crates/common/src/boxvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ impl<T> Extend<T> for BoxVec<T> {
};
let mut iter = iter.into_iter();
loop {
if std::ptr::eq(ptr, end_ptr) {
if core::ptr::eq(ptr, end_ptr) {
break;
}
if let Some(elt) = iter.next() {
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/cformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ impl<S> CFormatStrOrBytes<S> {
if !literal.is_empty() {
parts.push((
part_index,
CFormatPart::Literal(std::mem::take(&mut literal)),
CFormatPart::Literal(core::mem::take(&mut literal)),
));
}
let spec = CFormatSpecKeyed::parse(iter).map_err(|err| CFormatError {
Expand Down Expand Up @@ -816,7 +816,7 @@ impl<S> CFormatStrOrBytes<S> {

impl<S> IntoIterator for CFormatStrOrBytes<S> {
type Item = (usize, CFormatPart<S>);
type IntoIter = std::vec::IntoIter<Self::Item>;
type IntoIter = alloc::vec::IntoIter<Self::Item>;

fn into_iter(self) -> Self::IntoIter {
self.parts.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/encodings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ops::{self, Range};
use core::ops::{self, Range};

use num_traits::ToPrimitive;

Expand Down Expand Up @@ -260,7 +260,7 @@ pub mod errors {
use crate::str::UnicodeEscapeCodepoint;

use super::*;
use std::fmt::Write;
use core::fmt::Write;

pub struct Strict;

Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/fileutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use windows::{StatStruct, fstat};

#[cfg(not(windows))]
pub fn fstat(fd: crate::crt_fd::Borrowed<'_>) -> std::io::Result<StatStruct> {
let mut stat = std::mem::MaybeUninit::uninit();
let mut stat = core::mem::MaybeUninit::uninit();
unsafe {
let ret = libc::fstat(fd.as_raw(), stat.as_mut_ptr());
if ret == -1 {
Expand Down Expand Up @@ -441,7 +441,7 @@ pub mod windows {
// Open a file using std::fs::File and convert to FILE*
// Automatically handles path encoding and EINTR retries
pub fn fopen(path: &std::path::Path, mode: &str) -> std::io::Result<*mut libc::FILE> {
use std::ffi::CString;
use alloc::ffi::CString;
use std::fs::File;

// Currently only supports read mode
Expand Down
6 changes: 3 additions & 3 deletions crates/common/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use num_traits::FromPrimitive;
use num_traits::{Signed, cast::ToPrimitive};
use rustpython_literal::float;
use rustpython_literal::format::Case;
use std::ops::Deref;
use std::{cmp, str::FromStr};
use core::ops::Deref;
use core::{cmp, str::FromStr};

use crate::wtf8::{CodePoint, Wtf8, Wtf8Buf};

Expand Down Expand Up @@ -598,7 +598,7 @@ impl FormatSpec {
(Some(_), _) => Err(FormatSpecError::NotAllowed("Sign")),
(_, true) => Err(FormatSpecError::NotAllowed("Alternate form (#)")),
(_, _) => match num.to_u32() {
Some(n) if n <= 0x10ffff => Ok(std::char::from_u32(n).unwrap().to_string()),
Some(n) if n <= 0x10ffff => Ok(core::char::from_u32(n).unwrap().to_string()),
Some(_) | None => Err(FormatSpecError::CodeNotInRange),
},
},
Expand Down
8 changes: 4 additions & 4 deletions crates/common/src/hash.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use malachite_bigint::BigInt;
use num_traits::ToPrimitive;
use siphasher::sip::SipHasher24;
use std::hash::{BuildHasher, Hash, Hasher};
use core::hash::{BuildHasher, Hash, Hasher};

pub type PyHash = i64;
pub type PyUHash = u64;
Expand All @@ -19,9 +19,9 @@ pub const INF: PyHash = 314_159;
pub const NAN: PyHash = 0;
pub const IMAG: PyHash = MULTIPLIER;
pub const ALGO: &str = "siphash24";
pub const HASH_BITS: usize = std::mem::size_of::<PyHash>() * 8;
pub const HASH_BITS: usize = core::mem::size_of::<PyHash>() * 8;
// SipHasher24 takes 2 u64s as a seed
pub const SEED_BITS: usize = std::mem::size_of::<u64>() * 2 * 8;
pub const SEED_BITS: usize = core::mem::size_of::<u64>() * 2 * 8;

// pub const CUTOFF: usize = 7;

Expand Down Expand Up @@ -134,7 +134,7 @@ pub fn hash_bigint(value: &BigInt) -> PyHash {
Some(i) => mod_int(i),
None => (value % MODULUS).to_i64().unwrap_or_else(|| unsafe {
// SAFETY: MODULUS < i64::MAX, so value % MODULUS is guaranteed to be in the range of i64
std::hint::unreachable_unchecked()
core::hint::unreachable_unchecked()
}),
};
fix_sentinel(ret)
Expand Down
12 changes: 6 additions & 6 deletions crates/common/src/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ pub fn true_div(numerator: &BigInt, denominator: &BigInt) -> f64 {
let rational = Rational::from_integers_ref(numerator.into(), denominator.into());
match rational.rounding_into(RoundingMode::Nearest) {
// returned value is $t::MAX but still less than the original
(val, std::cmp::Ordering::Less) if val == f64::MAX => f64::INFINITY,
(val, core::cmp::Ordering::Less) if val == f64::MAX => f64::INFINITY,
// returned value is $t::MIN but still greater than the original
(val, std::cmp::Ordering::Greater) if val == f64::MIN => f64::NEG_INFINITY,
(val, core::cmp::Ordering::Greater) if val == f64::MIN => f64::NEG_INFINITY,
(val, _) => val,
}
}

pub fn float_to_ratio(value: f64) -> Option<(BigInt, BigInt)> {
let sign = match std::cmp::PartialOrd::partial_cmp(&value, &0.0)? {
std::cmp::Ordering::Less => Sign::Minus,
std::cmp::Ordering::Equal => return Some((BigInt::zero(), BigInt::one())),
std::cmp::Ordering::Greater => Sign::Plus,
let sign = match core::cmp::PartialOrd::partial_cmp(&value, &0.0)? {
core::cmp::Ordering::Less => Sign::Minus,
core::cmp::Ordering::Equal => return Some((BigInt::zero(), BigInt::one())),
core::cmp::Ordering::Greater => Sign::Plus,
};
Rational::try_from(value).ok().map(|x| {
let (numer, denom) = x.into_numerator_and_denominator();
Expand Down
2 changes: 2 additions & 0 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#![cfg_attr(all(target_os = "wasi", target_env = "p2"), feature(wasip2))]

extern crate alloc;

#[macro_use]
mod macros;
pub use macros::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl<L: Link> LinkedList<L, L::Target> {
// === rustpython additions ===

pub fn iter(&self) -> impl Iterator<Item = &L::Target> {
std::iter::successors(self.head, |node| unsafe {
core::iter::successors(self.head, |node| unsafe {
L::pointers(*node).as_ref().get_next()
})
.map(|ptr| unsafe { ptr.as_ref() })
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/lock/cell_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use lock_api::{
GetThreadId, RawMutex, RawRwLock, RawRwLockDowngrade, RawRwLockRecursive, RawRwLockUpgrade,
RawRwLockUpgradeDowngrade,
};
use std::{cell::Cell, num::NonZero};
use core::{cell::Cell, num::NonZero};

pub struct RawCellMutex {
locked: Cell<bool>,
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/lock/immutable_mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<'a, R: RawMutex, T: ?Sized> MapImmutable<'a, R, T> for MutexGuard<'a, R, T>
{
let raw = unsafe { MutexGuard::mutex(&s).raw() };
let data = f(&s) as *const U;
std::mem::forget(s);
core::mem::forget(s);
ImmutableMappedMutexGuard {
raw,
data,
Expand All @@ -38,7 +38,7 @@ impl<'a, R: RawMutex, T: ?Sized> ImmutableMappedMutexGuard<'a, R, T> {
{
let raw = s.raw;
let data = f(&s) as *const U;
std::mem::forget(s);
core::mem::forget(s);
ImmutableMappedMutexGuard {
raw,
data,
Expand Down
8 changes: 4 additions & 4 deletions crates/common/src/lock/thread_mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<'a, R: RawMutex, G: GetThreadId, T: ?Sized> ThreadMutexGuard<'a, R, G, T> {
) -> MappedThreadMutexGuard<'a, R, G, U> {
let data = f(&mut s).into();
let mu = &s.mu.raw;
std::mem::forget(s);
core::mem::forget(s);
MappedThreadMutexGuard {
mu,
data,
Expand All @@ -188,7 +188,7 @@ impl<'a, R: RawMutex, G: GetThreadId, T: ?Sized> ThreadMutexGuard<'a, R, G, T> {
if let Some(data) = f(&mut s) {
let data = data.into();
let mu = &s.mu.raw;
std::mem::forget(s);
core::mem::forget(s);
Ok(MappedThreadMutexGuard {
mu,
data,
Expand Down Expand Up @@ -241,7 +241,7 @@ impl<'a, R: RawMutex, G: GetThreadId, T: ?Sized> MappedThreadMutexGuard<'a, R, G
) -> MappedThreadMutexGuard<'a, R, G, U> {
let data = f(&mut s).into();
let mu = s.mu;
std::mem::forget(s);
core::mem::forget(s);
MappedThreadMutexGuard {
mu,
data,
Expand All @@ -255,7 +255,7 @@ impl<'a, R: RawMutex, G: GetThreadId, T: ?Sized> MappedThreadMutexGuard<'a, R, G
if let Some(data) = f(&mut s) {
let data = data.into();
let mu = s.mu;
std::mem::forget(s);
core::mem::forget(s);
Ok(MappedThreadMutexGuard {
mu,
data,
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/rc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(not(feature = "threading"))]
use std::rc::Rc;
use alloc::rc::Rc;
#[cfg(feature = "threading")]
use std::sync::Arc;

Expand Down
8 changes: 4 additions & 4 deletions crates/common/src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::wtf8::{CodePoint, Wtf8, Wtf8Buf};
use ascii::{AsciiChar, AsciiStr, AsciiString};
use core::fmt;
use core::sync::atomic::Ordering::Relaxed;
use std::ops::{Bound, RangeBounds};
use core::ops::{Bound, RangeBounds};

#[cfg(not(target_arch = "wasm32"))]
#[allow(non_camel_case_types)]
Expand All @@ -22,7 +22,7 @@ pub enum StrKind {
Wtf8,
}

impl std::ops::BitOr for StrKind {
impl core::ops::BitOr for StrKind {
type Output = Self;

fn bitor(self, other: Self) -> Self {
Expand Down Expand Up @@ -262,7 +262,7 @@ impl StrData {
pub fn as_str(&self) -> Option<&str> {
self.kind
.is_utf8()
.then(|| unsafe { std::str::from_utf8_unchecked(self.data.as_bytes()) })
.then(|| unsafe { core::str::from_utf8_unchecked(self.data.as_bytes()) })
}

pub fn as_ascii(&self) -> Option<&AsciiStr> {
Expand All @@ -282,7 +282,7 @@ impl StrData {
PyKindStr::Ascii(unsafe { AsciiStr::from_ascii_unchecked(self.data.as_bytes()) })
}
StrKind::Utf8 => {
PyKindStr::Utf8(unsafe { std::str::from_utf8_unchecked(self.data.as_bytes()) })
PyKindStr::Utf8(unsafe { core::str::from_utf8_unchecked(self.data.as_bytes()) })
}
StrKind::Wtf8 => PyKindStr::Wtf8(&self.data),
}
Expand Down