no_std clippy by youknowone · Pull Request #7043 · RustPython/RustPython
📝 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
- finish no_std clippy #6587: Similar no-std/core+alloc migration across many stdlib modules (strong overlap in approach and affected files).
- Fix asyncio related compiler/library issues #6837: Touches
crates/codegen/src/compile.rsand may conflict with changes around t-string/template handling. - Upgrade threading to 3.13.11; sys.setprofile & impl more threading #6691: Changes threading types/APIs (ThreadHandle/ShutdownEntry/Arc/Weak) similar to the thread-related type migrations here.
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.
Comment @coderabbitai help to get the list of available commands and usage tips.