◐ Shell
reader mode source ↗
Skip to content

no_std clippy#7043

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

no_std clippy#7043
youknowone merged 2 commits into
RustPython:mainfrom
youknowone:no_std

Conversation

@youknowone

@youknowone youknowone commented Feb 8, 2026

Copy link
Copy Markdown
Member

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

coderabbitai Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor
📝 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

github-actions Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

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
@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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hide comment

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);

@ShaharNaveh ShaharNaveh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hide comment

Great!

@youknowone youknowone disabled auto-merge February 8, 2026 07:49
Hide details View details @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