Skip to content

no_std clippy#7043

Merged
youknowone merged 2 commits intoRustPython:mainfrom
youknowone:no_std
Feb 8, 2026
Merged

no_std clippy#7043
youknowone merged 2 commits intoRustPython:mainfrom
youknowone:no_std

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Feb 8, 2026

finish #6380

Summary by CodeRabbit

Release Notes

  • Refactor

    • Reduced reliance on the standard library to improve compatibility with restricted/no-std environments and broaden platform support.
    • Multiple internal imports and memory/pointer handling paths migrated to core/alloc equivalents with no behavioral changes.
  • Chores

    • Enabled additional Clippy lints (including suspicious and correctness) and clarified lint annotations for cross-platform code.
  • Compatibility

    • Small, targeted public type adjustments to threading/module state to align with the allocator/core changes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 8, 2026

📝 Walkthrough

Walkthrough

This PR enables additional Clippy lints and systematically replaces many std:: usages with core:: and alloc:: equivalents across the codebase (memory, pointers, atomics, collections, FFI and threading types) to align with no-std/no-std-like constraints.

Changes

Cohort / File(s) Summary
Clippy Configuration
Cargo.toml
Uncommented/enabled clippy lints: alloc_instead_of_core, std_instead_of_alloc, std_instead_of_core; added suspicious and correctness lint groups set to warn.
Memory & Pointer core:: Migration
crates/.../codegen/src/compile.rs, crates/common/src/crt_fd.rs, crates/common/src/fileutils.rs, crates/stdlib/src/mmap.rs, crates/vm/src/stdlib/nt.rs, crates/vm/src/stdlib/sys.rs, crates/vm/src/windows.rs, crates/vm/src/stdlib/winapi.rs, crates/vm/src/stdlib/winreg.rs
Replaced std::mem::*, std::ptr::*, std::mem::MaybeUninit, std::mem::zeroed, and std::mem::size_of* usages with core:: equivalents for initialization, sizing, and null pointers.
Slices / Iterators / Formatting Migration
crates/stdlib/src/_sqlite3.rs, crates/stdlib/src/math.rs, crates/stdlib/src/socket.rs, crates/stdlib/src/ssl.rs, crates/vm/src/stdlib/io.rs, crates/vm/src/stdlib/msvcrt.rs
Swapped std::slice, std::iter, std::fmt and related calls with core::slice, core::iter, core::fmt equivalents (including Debug impl updates).
Atomic Types Migration
crates/stdlib/src/_asyncio.rs, crates/stdlib/src/posixsubprocess.rs, crates/vm/src/builtins/template.rs, crates/vm/src/stdlib/_abc.rs, crates/vm/src/stdlib/signal.rs, crates/vm/src/vm/interpreter.rs, crates/vm/src/vm/mod.rs
Replaced std::sync::atomic::{...} imports and usages with core::sync::atomic counterparts; updated struct fields/initializers and Ordering references (notably PyTemplateIter fields).
Arc/Weak & Collections Migration
crates/stdlib/src/multiprocessing.rs, crates/stdlib/src/overlapped.rs, crates/stdlib/src/thread.rs, crates/vm/src/vm/thread.rs, crates/vm/src/vm/interpreter.rs, crates/vm/src/vm/mod.rs
Replaced std::sync::Arc/Weak with alloc::sync::{Arc, Weak} and moved std::collections::BTreeMap uses to alloc::collections::BTreeMap/local imports; several public struct fields/types updated accordingly (thread-related types).
FFI / CString / c_void Migration
crates/common/src/fileutils.rs, crates/stdlib/src/multiprocessing.rs, crates/stdlib/src/os.rs, crates/vm/src/stdlib/ctypes.rs
Replaced std::ffi::CString with alloc::ffi::CString in allocation contexts; switched std::ffi::c_void to core::ffi::c_void in function-pointer signatures.
Duration / Time types Migration
crates/stdlib/src/ssl.rs, crates/vm/src/stdlib/time.rs
Replaced std::time::Duration with core::time::Duration in function parameters/usage and corresponding duration computations.
Clippy allow attributes & minor annotations
crates/vm/src/stdlib/ctypes/base.rs, crates/vm/src/stdlib/ctypes/function.rs, crates/vm/src/stdlib/ctypes/pointer.rs, crates/vm/src/stdlib/ctypes/simple.rs, crates/vm/src/stdlib/io.rs
Added/expanded clippy allow attributes (e.g., clippy::useless_conversion, clippy::unnecessary_cast) with reason strings for platform-specific wchar_t conversions and added small comment/lint tweaks.
Small std→core/alloc swaps in VM internals
crates/vm/src/builtins/function.rs, crates/vm/src/builtins/tuple.rs, crates/vm/src/frame.rs, crates/vm/src/signal.rs, crates/vm/src/builtins/template.rs, crates/vm/src/stdlib/ctypes/*, crates/vm/src/stdlib/io.rs, crates/vm/src/stdlib/msvcrt.rs
Replaced scattered std:: usages (e.g., mem::take, mem::replace, hint::unreachable_unchecked, cell::Cell, ptr::null_mut) with core:: equivalents; atomic and field signature adjustments where applicable.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

Suggested reviewers

  • ShaharNaveh
  • arihant2math

"🐰 I hopped through code at break of dawn,
Swapped std for core before the lawn,
Pointers neat and atomics bright,
Clippy nods as I take flight —
A tiny hop, a cleaner night."

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'no_std clippy' is vague and generic, using non-descriptive terms that don't clearly convey the changeset's main objective despite referencing a related initiative. Revise the title to be more specific and descriptive of the primary changes, such as 'Replace std library imports with core/alloc equivalents for no_std compatibility' or reference the issue more explicitly.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 96.75% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2026

Code has been automatically formatted

The code in this PR has been formatted using:

  • cargo fmt --all
    Please pull the latest changes before pushing again:
git pull origin no_std

@youknowone youknowone force-pushed the no_std branch 5 times, most recently from 44bf6bf to da9ad35 Compare February 8, 2026 06:21
#[cfg(not(windows))]
{
// wchar_t is i32 on some platforms and u32 on others
#[allow(clippy::useless_conversion)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[allow(clippy::useless_conversion)]
#[allow(clippy::useless_conversion, reason = "wchar_t is i32 on some platforms and u32 on others")]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

#[cfg(not(windows))]
{
// wchar_t is i32 on some platforms and u32 on others
#[allow(clippy::useless_conversion)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here

let addr = (ptr_value as isize + cur * wchar_size as isize) as *const libc::wchar_t;
unsafe {
// wchar_t is i32 on some platforms and u32 on others
#[allow(clippy::unnecessary_cast)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@youknowone you missed this one:)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran a project-wide appliance task. Let's handle this there

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, that task didn't catch this one 🤦

#[cfg(not(windows))]
{
// wchar_t is i32 on some platforms and u32 on others
#[allow(clippy::useless_conversion)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@youknowone youknowone marked this pull request as ready for review February 8, 2026 07:18
@youknowone youknowone enabled auto-merge (squash) February 8, 2026 07:18
let addr = (ptr_value as isize + cur * wchar_size as isize) as *const libc::wchar_t;
unsafe {
// wchar_t is i32 on some platforms and u32 on others
#[allow(clippy::unnecessary_cast)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@youknowone you missed this one:)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@crates/vm/src/stdlib/thread.rs`:
- Around line 20-23: The import is pulling fmt from alloc which triggers the
alloc_instead_of_core lint; change the use to import fmt from core (so types
like fmt::Debug, fmt::Formatter, fmt::Result come from core::fmt) while keeping
sync::{Arc, Weak} from alloc; update the use statement that currently reads use
alloc::{ fmt, sync::{Arc, Weak}, }; to import core::fmt instead and leave Arc
and Weak unchanged, and ensure any references to fmt types (Debug, Formatter,
Result) remain correct.
🧹 Nitpick comments (1)
crates/vm/src/stdlib/signal.rs (1)

31-31: Nit: use the existing atomic alias for brevity.

Line 15 already imports core::sync::atomic::{self, Ordering}, so the fully qualified core::sync::atomic::AtomicBool can be simplified.

♻️ Suggested simplification
-            static WAKEUP_IS_SOCKET: core::sync::atomic::AtomicBool = core::sync::atomic::AtomicBool::new(false);
+            static WAKEUP_IS_SOCKET: atomic::AtomicBool = atomic::AtomicBool::new(false);

Comment on lines +20 to +23
use alloc::{
fmt,
sync::{Arc, Weak},
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# Check the current imports at lines 20-23
sed -n '15,30p' crates/vm/src/stdlib/thread.rs

# Search for Clippy lint allow/deny configuration
rg -n 'allow|deny|warn' crates/vm/src/stdlib/thread.rs | head -20

# Check if there's a clippy.toml or Cargo.toml with lint configuration
find . -name "clippy.toml" -o -name "Cargo.toml" | grep -E "(^./Cargo.toml|clippy)" | head -5

# Check for Clippy lint configuration in the workspace Cargo.toml
rg -A 20 '\[lints\]' crates/vm/Cargo.toml

Repository: RustPython/RustPython

Length of output: 932


🏁 Script executed:

# Check the workspace Cargo.toml for lint configuration
rg -A 50 '\[lints\]' Cargo.toml

# Check for alloc_instead_of_core and std_instead_of_alloc lint settings
rg 'alloc_instead_of_core|std_instead_of_alloc' Cargo.toml

# Examine what fmt is actually used for in the file
rg -n 'fmt::' crates/vm/src/stdlib/thread.rs | head -20

Repository: RustPython/RustPython

Length of output: 570


🏁 Script executed:

# Double-check the full [lints] section to understand the context
sed -n '/\[lints\]/,/^\[/p' Cargo.toml | head -50

# Verify this is the workspace lints
head -20 Cargo.toml

Repository: RustPython/RustPython

Length of output: 827


🏁 Script executed:

# Find the workspace Cargo.toml and check the [lints] section
find . -name "Cargo.toml" -type f | xargs grep -l "workspace = true" | head -1

# Look for [lints] in the root Cargo.toml
rg -B 5 -A 20 'alloc_instead_of_core' .

# Also check if alloc::fmt is re-exported from core::fmt
python3 <<'EOF'
# Verify that alloc::fmt re-exports from core::fmt
# This is Rust standard library fact-checking
print("In Rust standard library:")
print("- alloc::fmt re-exports core::fmt and adds format! macro")
print("- core::fmt contains: Debug, Formatter, Result, etc.")
print("- alloc_instead_of_core lint warns when using alloc for types from core")
print("- std_instead_of_alloc lint warns when using std for types from alloc")
print("\nFor fmt::Debug, fmt::Formatter, fmt::Result -> these are core::fmt types")
print("Using alloc::fmt for these would trigger alloc_instead_of_core lint")
EOF

Repository: RustPython/RustPython

Length of output: 961


Use core::fmt instead of alloc::fmt to comply with the alloc_instead_of_core Clippy lint.

The workspace has alloc_instead_of_core = "warn" enabled. Since fmt::Debug, fmt::Formatter, and fmt::Result are core::fmt types (not alloc::fmt), importing from alloc::fmt triggers this lint. The alloc::sync::{Arc, Weak} import is correct.

Suggested fix
-use alloc::{
-    fmt,
-    sync::{Arc, Weak},
-};
+use alloc::sync::{Arc, Weak};
+use core::fmt;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
use alloc::{
fmt,
sync::{Arc, Weak},
};
use alloc::sync::{Arc, Weak};
use core::fmt;
🤖 Prompt for AI Agents
In `@crates/vm/src/stdlib/thread.rs` around lines 20 - 23, The import is pulling
fmt from alloc which triggers the alloc_instead_of_core lint; change the use to
import fmt from core (so types like fmt::Debug, fmt::Formatter, fmt::Result come
from core::fmt) while keeping sync::{Arc, Weak} from alloc; update the use
statement that currently reads use alloc::{ fmt, sync::{Arc, Weak}, }; to import
core::fmt instead and leave Arc and Weak unchanged, and ensure any references to
fmt types (Debug, Formatter, Result) remain correct.

Copy link
Contributor

@ShaharNaveh ShaharNaveh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@youknowone youknowone disabled auto-merge February 8, 2026 07:49
@youknowone youknowone merged commit 07fc6ee into RustPython:main Feb 8, 2026
12 of 13 checks passed
@youknowone youknowone deleted the no_std branch February 8, 2026 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants