◐ Shell
clean mode source ↗

Adding + Fixing Clippy rules to better align with #[no_std] by terryluan12 · Pull Request #6570 · RustPython/RustPython

Changes Summary

This PR addresses issue #6380 by systematically migrating the RustPython codebase to prefer core:: and alloc:: imports over std:: imports where appropriate, following Rust best practices for no-std compatibility. The work involves 184 changed files across all crates (codegen, common, compiler-core, stdlib, vm, etc.) and concludes with an auto-formatting pass to maintain consistency.

Type: refactoring

Components Affected: codegen, common, compiler-core, compiler, derive-impl, derive, literal, sre_engine, stdlib, vm, venvlauncher, examples

Files Changed
File Summary Change Impact
crates/common/src/str.rs Replaced std:: imports with core:: equivalents (ops, fmt, slice, iter, mem) where applicable, improved no-std support ✏️ 🔴
crates/stdlib/src/array.rs Migrated std:: to core:: and alloc:: for mem operations, memory layout calculations, and slice construction ✏️ 🔴
crates/codegen/src/lib.rs Added extern crate alloc declaration for proper allocation support in no-std context ✏️ 🟡
crates/compiler-core/src/lib.rs Added extern crate alloc declaration ✏️ 🟡
crates/common/src/lib.rs Added extern crate alloc declaration ✏️ 🟡
Cargo.toml Updated workspace lints to include clippy rules for std_instead_of_core, alloc_instead_of_core, std_instead_of_alloc ✏️ 🟡
Architecture Impact
  • New Patterns: no-std compatibility, core/alloc crate separation, standards-based import organization
  • Dependencies: Added: clippy lint rules (std_instead_of_core, std_instead_of_alloc, alloc_instead_of_core)
  • Coupling: Reduces coupling to std library by preferring core:: and alloc:: modules, enabling better no-std support and potentially facilitating WASM targets

Risk Areas: Widespread import changes across 184 files could introduce subtle runtime behavior changes if core:: and std:: implementations differ, Changes to memory safety operations (mem::size_of, mem::swap, slice operations) need verification that no subtle bugs were introduced, Clippy lint enforcement (alloc_instead_of_core, std_instead_of_alloc) could break existing tooling if lints are too strict, Import reordering (as part of rustfmt) could affect code readability or introduce merge conflicts

Suggestions
  • Verify that no-std compilation works correctly with these changes (test with cargo build --no-default-features)
  • Run full test suite to ensure behavioral equivalence between std:: and core:: imports
  • Check that all memory safety operations (ManuallyDrop, size_of, swap, etc.) have identical semantics after refactoring
  • Review the handling of platform-specific features (Windows, WASM) to ensure no regressions
  • Validate that the new Cargo.toml lint rules don't incorrectly flag legitimate uses of std

Full review in progress... | Powered by diffray