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
Finished migrating the rest of the warnings manually
  • Loading branch information
terryluan12 committed Dec 29, 2025
commit ae6f6d862393fd66b301796a8b561570c456a042
3 changes: 2 additions & 1 deletion crates/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ use rustpython_compiler_core::{
},
};
use rustpython_wtf8::Wtf8Buf;
use std::{borrow::Cow, collections::HashSet};
use alloc::borrow::Cow;
use std::collections::HashSet;

const MAXBLOCKS: usize = 20;

Expand Down
3 changes: 2 additions & 1 deletion crates/codegen/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rustpython_compiler_core::SourceLocation;
use std::fmt::{self, Display};
use alloc::fmt;
use core::fmt::Display;
use thiserror::Error;

#[derive(Debug)]
Expand Down
6 changes: 3 additions & 3 deletions crates/codegen/src/ir.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ops;
use core::ops;

use crate::{IndexMap, IndexSet, error::InternalError};
use rustpython_compiler_core::{
Expand Down Expand Up @@ -198,7 +198,7 @@ impl CodeInfo {
*arg = new_arg;
}
let (extras, lo_arg) = arg.split();
locations.extend(std::iter::repeat_n(info.location, arg.instr_size()));
locations.extend(core::iter::repeat_n(info.location, arg.instr_size()));
instructions.extend(
extras
.map(|byte| CodeUnit::new(Instruction::ExtendedArg, byte))
Expand Down Expand Up @@ -401,7 +401,7 @@ fn stackdepth_push(

fn iter_blocks(blocks: &[Block]) -> impl Iterator<Item = (BlockIdx, &Block)> + '_ {
let mut next = BlockIdx(0);
std::iter::from_fn(move || {
core::iter::from_fn(move || {
if next == BlockIdx::NULL {
return None;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/codegen/src/string_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! after ruff has already successfully parsed the string literal, meaning
//! we don't need to do any validation or error handling.

use std::convert::Infallible;
use core::convert::Infallible;

use ruff_python_ast::{AnyStringFlags, StringFlags};
use rustpython_wtf8::{CodePoint, Wtf8, Wtf8Buf};
Expand Down Expand Up @@ -96,7 +96,7 @@ impl StringParser {
}

// OK because radix_bytes is always going to be in the ASCII range.
let radix_str = std::str::from_utf8(&radix_bytes[..len]).expect("ASCII bytes");
let radix_str = core::str::from_utf8(&radix_bytes[..len]).expect("ASCII bytes");
let value = u32::from_str_radix(radix_str, 8).unwrap();
char::from_u32(value).unwrap()
}
Expand Down
8 changes: 4 additions & 4 deletions crates/codegen/src/symboltable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use ruff_python_ast::{
};
use ruff_text_size::{Ranged, TextRange};
use rustpython_compiler_core::{PositionEncoding, SourceFile, SourceLocation};
use std::{borrow::Cow, fmt};
use alloc::{borrow::Cow, fmt};

/// Captures all symbols in the current scope, and has a list of sub-scopes in this scope.
#[derive(Clone)]
Expand Down Expand Up @@ -262,7 +262,7 @@ type SymbolMap = IndexMap<String, Symbol>;

mod stack {
use std::panic;
use std::ptr::NonNull;
use core::ptr::NonNull;
pub struct StackStack<T> {
v: Vec<NonNull<T>>,
}
Expand Down Expand Up @@ -325,7 +325,7 @@ struct SymbolTableAnalyzer {

impl SymbolTableAnalyzer {
fn analyze_symbol_table(&mut self, symbol_table: &mut SymbolTable) -> SymbolTableResult {
let symbols = std::mem::take(&mut symbol_table.symbols);
let symbols = core::mem::take(&mut symbol_table.symbols);
let sub_tables = &mut *symbol_table.sub_tables;

let mut info = (symbols, symbol_table.typ);
Expand Down Expand Up @@ -689,7 +689,7 @@ impl SymbolTableBuilder {
fn leave_scope(&mut self) {
let mut table = self.tables.pop().unwrap();
// Save the collected varnames to the symbol table
table.varnames = std::mem::take(&mut self.current_varnames);
table.varnames = core::mem::take(&mut self.current_varnames);
self.tables.last_mut().unwrap().sub_tables.push(table);
}

Expand Down
3 changes: 2 additions & 1 deletion crates/codegen/src/unparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use ruff_python_ast::{
use ruff_text_size::Ranged;
use rustpython_compiler_core::SourceFile;
use rustpython_literal::escape::{AsciiEscape, UnicodeEscape};
use alloc::fmt::{self, Display as _};
use alloc::fmt;
use core::fmt::Display as _;

mod precedence {
macro_rules! precedence {
Expand Down
6 changes: 2 additions & 4 deletions crates/common/src/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ use crate::lock::{
MapImmutable, PyImmutableMappedMutexGuard, PyMappedMutexGuard, PyMappedRwLockReadGuard,
PyMappedRwLockWriteGuard, PyMutexGuard, PyRwLockReadGuard, PyRwLockWriteGuard,
};
use std::{
fmt,
ops::{Deref, DerefMut},
};
use alloc::fmt;
use core::ops::{Deref, DerefMut};

macro_rules! impl_from {
($lt:lifetime, $gen:ident, $t:ty, $($var:ident($from:ty),)*) => {
Expand Down
8 changes: 4 additions & 4 deletions crates/common/src/boxvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
//! An unresizable vector backed by a `Box<[T]>`

#![allow(clippy::needless_lifetimes)]

use std::{
use alloc::{fmt, slice};
use core::{
borrow::{Borrow, BorrowMut},
cmp, fmt,
cmp,
mem::{self, MaybeUninit},
ops::{Bound, Deref, DerefMut, RangeBounds},
ptr, slice,
ptr,
};

pub struct BoxVec<T> {
Expand Down
5 changes: 3 additions & 2 deletions crates/common/src/cformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use itertools::Itertools;
use malachite_bigint::{BigInt, Sign};
use num_traits::Signed;
use rustpython_literal::{float, format::Case};
use std::{
cmp, fmt,
use alloc::fmt;
use core::{
cmp,
iter::{Enumerate, Peekable},
str::FromStr,
};
Expand Down
4 changes: 3 additions & 1 deletion crates/common/src/crt_fd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! A module implementing an io type backed by the C runtime's file descriptors, i.e. what's
//! returned from libc::open, even on windows.

use std::{cmp, ffi, fmt, io};
use alloc::fmt;
use core::cmp;
use std::{ffi, io};

#[cfg(not(windows))]
use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
Expand Down
6 changes: 3 additions & 3 deletions crates/common/src/fileutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub mod windows {
}

fn file_time_to_time_t_nsec(in_ptr: &FILETIME) -> (libc::time_t, libc::c_int) {
let in_val: i64 = unsafe { std::mem::transmute_copy(in_ptr) };
let in_val: i64 = unsafe { core::mem::transmute_copy(in_ptr) };
let nsec_out = (in_val % 10_000_000) * 100; // FILETIME is in units of 100 nsec.
let time_out = (in_val / 10_000_000) - SECS_BETWEEN_EPOCHS;
(time_out, nsec_out as _)
Expand Down Expand Up @@ -204,7 +204,7 @@ pub mod windows {
let st_nlink = info.nNumberOfLinks as i32;

let st_ino = if let Some(id_info) = id_info {
let file_id: [u64; 2] = unsafe { std::mem::transmute_copy(&id_info.FileId) };
let file_id: [u64; 2] = unsafe { core::mem::transmute_copy(&id_info.FileId) };
file_id
} else {
let ino = ((info.nFileIndexHigh as u64) << 32) + info.nFileIndexLow as u64;
Expand Down Expand Up @@ -313,7 +313,7 @@ pub mod windows {
unsafe { GetProcAddress(module, name.as_bytes_with_nul().as_ptr()) }
{
Some(unsafe {
std::mem::transmute::<
core::mem::transmute::<
unsafe extern "system" fn() -> isize,
unsafe extern "system" fn(
*const u16,
Expand Down
3 changes: 2 additions & 1 deletion crates/common/src/lock/immutable_mutex.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![allow(clippy::needless_lifetimes)]

use lock_api::{MutexGuard, RawMutex};
use std::{fmt, marker::PhantomData, ops::Deref};
use alloc::fmt;
use core::{marker::PhantomData, ops::Deref};

/// A mutex guard that has an exclusive lock, but only an immutable reference; useful if you
/// need to map a mutex guard with a function that returns an `&T`. Construct using the
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/lock/thread_mutex.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![allow(clippy::needless_lifetimes)]

use lock_api::{GetThreadId, GuardNoSend, RawMutex};
use std::{
use alloc::fmt;
use core::{
cell::UnsafeCell,
fmt,
marker::PhantomData,
ops::{Deref, DerefMut},
ptr::NonNull,
Expand Down
3 changes: 2 additions & 1 deletion crates/common/src/os.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// spell-checker:disable
// TODO: we can move more os-specific bindings/interfaces from stdlib::{os, posix, nt} to here

use std::{io, process::ExitCode, str::Utf8Error};
use core::str::Utf8Error;
use std::{io, process::ExitCode};

/// Convert exit code to std::process::ExitCode
///
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/rc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(not(feature = "threading"))]
use alloc::rc::Rc;
#[cfg(feature = "threading")]
use std::sync::Arc;
use alloc::sync::Arc;

// type aliases instead of new-types because you can't do `fn method(self: PyRc<Self>)` with a
// newtype; requires the arbitrary_self_types unstable feature
Expand Down
13 changes: 7 additions & 6 deletions crates/compiler-core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use itertools::Itertools;
use malachite_bigint::BigInt;
use num_complex::Complex64;
use rustpython_wtf8::{Wtf8, Wtf8Buf};
use std::{collections::BTreeSet, fmt, hash, marker::PhantomData, mem, num::NonZeroU8, ops::Deref};
use alloc::{collections::BTreeSet, fmt};
use core::{hash, marker::PhantomData, mem, num::NonZeroU8, ops::Deref};

/// Oparg values for [`Instruction::ConvertValue`].
///
Expand Down Expand Up @@ -506,7 +507,7 @@ impl<T: OpArgType> Eq for Arg<T> {}

impl<T: OpArgType> fmt::Debug for Arg<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Arg<{}>", std::any::type_name::<T>())
write!(f, "Arg<{}>", core::any::type_name::<T>())
}
}

Expand Down Expand Up @@ -880,7 +881,7 @@ impl From<Instruction> for u8 {
#[inline]
fn from(ins: Instruction) -> Self {
// SAFETY: there's no padding bits
unsafe { std::mem::transmute::<Instruction, Self>(ins) }
unsafe { core::mem::transmute::<Instruction, Self>(ins) }
}
}

Expand All @@ -890,7 +891,7 @@ impl TryFrom<u8> for Instruction {
#[inline]
fn try_from(value: u8) -> Result<Self, MarshalError> {
if value <= u8::from(LAST_INSTRUCTION) {
Ok(unsafe { std::mem::transmute::<u8, Self>(value) })
Ok(unsafe { core::mem::transmute::<u8, Self>(value) })
} else {
Err(MarshalError::InvalidBytecode)
}
Expand Down Expand Up @@ -1027,7 +1028,7 @@ impl PartialEq for ConstantData {
(Boolean { value: a }, Boolean { value: b }) => a == b,
(Str { value: a }, Str { value: b }) => a == b,
(Bytes { value: a }, Bytes { value: b }) => a == b,
(Code { code: a }, Code { code: b }) => std::ptr::eq(a.as_ref(), b.as_ref()),
(Code { code: a }, Code { code: b }) => core::ptr::eq(a.as_ref(), b.as_ref()),
(Tuple { elements: a }, Tuple { elements: b }) => a == b,
(None, None) => true,
(Ellipsis, Ellipsis) => true,
Expand All @@ -1053,7 +1054,7 @@ impl hash::Hash for ConstantData {
Boolean { value } => value.hash(state),
Str { value } => value.hash(state),
Bytes { value } => value.hash(state),
Code { code } => std::ptr::hash(code.as_ref(), state),
Code { code } => core::ptr::hash(code.as_ref(), state),
Tuple { elements } => elements.hash(state),
None => {}
Ellipsis => {}
Expand Down
2 changes: 2 additions & 0 deletions crates/compiler-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/main/logo.png")]
#![doc(html_root_url = "https://docs.rs/rustpython-compiler-core/")]

extern crate alloc;

pub mod bytecode;
pub mod frozen;
pub mod marshal;
Expand Down
10 changes: 5 additions & 5 deletions crates/compiler-core/src/marshal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{OneIndexed, SourceLocation, bytecode::*};
use malachite_bigint::{BigInt, Sign};
use num_complex::Complex64;
use rustpython_wtf8::Wtf8;
use std::convert::Infallible;
use core::convert::Infallible;

pub const FORMAT_VERSION: u32 = 4;

Expand Down Expand Up @@ -32,8 +32,8 @@ impl core::fmt::Display for MarshalError {
}
}

impl From<std::str::Utf8Error> for MarshalError {
fn from(_: std::str::Utf8Error) -> Self {
impl From<core::str::Utf8Error> for MarshalError {
fn from(_: core::str::Utf8Error) -> Self {
Self::InvalidUtf8
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@ pub trait Read {
}

fn read_str(&mut self, len: u32) -> Result<&str> {
Ok(std::str::from_utf8(self.read_slice(len)?)?)
Ok(core::str::from_utf8(self.read_slice(len)?)?)
}

fn read_wtf8(&mut self, len: u32) -> Result<&Wtf8> {
Expand Down Expand Up @@ -147,7 +147,7 @@ pub(crate) trait ReadBorrowed<'a>: Read {
fn read_slice_borrow(&mut self, n: u32) -> Result<&'a [u8]>;

fn read_str_borrow(&mut self, len: u32) -> Result<&'a str> {
Ok(std::str::from_utf8(self.read_slice_borrow(len)?)?)
Ok(core::str::from_utf8(self.read_slice_borrow(len)?)?)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/compiler-core/src/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub enum Mode {
BlockExpr,
}

impl std::str::FromStr for Mode {
impl core::str::FromStr for Mode {
type Err = ModeParseError;

// To support `builtins.compile()` `mode` argument
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct ParseError {
}

impl ::core::fmt::Display for ParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
self.error.fmt(f)
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/derive-impl/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub(crate) struct ContentItemInner<T> {
}

pub(crate) trait ContentItem {
type AttrName: std::str::FromStr + core::fmt::Display;
type AttrName: core::str::FromStr + core::fmt::Display;

fn inner(&self) -> &ContentItemInner<Self::AttrName>;
fn index(&self) -> usize {
Expand Down Expand Up @@ -529,7 +529,7 @@ impl ExceptionItemMeta {
}
}

impl std::ops::Deref for ExceptionItemMeta {
impl core::ops::Deref for ExceptionItemMeta {
type Target = ClassItemMeta;
fn deref(&self) -> &Self::Target {
&self.0
Expand Down
2 changes: 1 addition & 1 deletion crates/literal/src/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn format_fixed(precision: usize, magnitude: f64, case: Case, alternate_form
match magnitude {
magnitude if magnitude.is_finite() => {
let point = decimal_point_or_empty(precision, alternate_form);
let precision = std::cmp::min(precision, u16::MAX as usize);
let precision = core::cmp::min(precision, u16::MAX as usize);
format!("{magnitude:.precision$}{point}")
}
magnitude if magnitude.is_nan() => format_nan(case),
Expand Down
2 changes: 1 addition & 1 deletion crates/sre_engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ fn _count<S: StrDrive>(
ctx: &mut MatchContext,
max_count: usize,
) -> usize {
let max_count = std::cmp::min(max_count, ctx.remaining_chars(req));
let max_count = core::cmp::min(max_count, ctx.remaining_chars(req));
let end = ctx.cursor.position + max_count;
let opcode = SreOpcode::try_from(ctx.peek_code(req, 0)).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion crates/sre_engine/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct StringCursor {
impl Default for StringCursor {
fn default() -> Self {
Self {
ptr: std::ptr::null(),
ptr: core::ptr::null(),
position: 0,
}
}
Expand Down
Loading