◐ Shell
clean mode source ↗

derive `Copy` where possible by ShaharNaveh · Pull Request #6844 · RustPython/RustPython

📝 Walkthrough

Walkthrough

Adds many Clone/Copy derives across crates, a workspace lint, small API fields (buffer release/retain), a TryLockThreadError and SingleThreadId change, and makes ExceptionTableEntry::new a const fn. No behavioral control-flow changes beyond by-value usage where derives permit it.

Changes

Cohort / File(s) Summary
Lint Configuration
\Cargo.toml``
Added workspace lint: workspace.lints.rust.missing_copy_implementations = "warn".
Codegen
\crates/codegen/src/compile.rs`, `crates/codegen/src/error.rs`, `crates/codegen/src/ir.rs`, `crates/codegen/src/symboltable.rs``
Added Clone, Copy derives to CompileOpts, DoneWithFuture, PatternUnreachableReason, InstructionInfo, ExceptHandlerInfo, SymbolUsage; replaced some .clone() with by-value uses in ir.rs.
Common — formats/encodings/hash/int/str/cformat
\crates/common/src/format.rs`, `crates/common/src/encodings.rs`, `crates/common/src/hash.rs`, `crates/common/src/int.rs`, `crates/common/src/str.rs`, `crates/common/src/cformat.rs``
Added Clone, Copy derives to many small/public types and error structs (Format*, encoding errors, HashSecret, BytesToIntError, UnicodeEscapeCodepoint, CFormatErrorType, CFormatError).
Common — locking / single-thread id
\crates/common/src/lock/thread_mutex.rs`, `crates/common/src/lock/cell_lock.rs``
Added TryLockThreadError (Clone/Copy), introduced SingleThreadId (Clone/Copy) with unsafe impl GetThreadId using NonZero::new_unchecked(1), and adjusted try_lock-related debug paths.
Compiler-core
\crates/compiler-core/src/bytecode.rs`, `crates/compiler-core/src/marshal.rs`, `crates/compiler-core/src/mode.rs``
ExceptionTableEntry now derives Copy and its new is pub const fn; added Clone, Copy to MarshalError and ModeParseError.
SRE engine
\crates/sre_engine/src/constants.rs``
Added Clone, Copy derives to SreOpcode, SreAtCode, SreCatCode, and SreInfo.
VM — builtins & core types
\crates/vm/src/builtins/.rs`, `crates/vm/src/dict_inner.rs`, `crates/vm/src/sliceable.rs`, `crates/vm/src/function/`, `crates/vm/src/function/number.rs``
Widespread addition of Clone, Copy to many VM/public types (singletons, ellipsis, base object, namespace → unit-like, module types, method defs, ArgInto* types, DictSize, SequenceIndex, SaturatedSliceIter, etc.); added MemberGetter and MemberSetter enums.
VM — protocol & buffers
\crates/vm/src/protocol/buffer.rs`, `crates/vm/src/protocol/mapping.rs`, `crates/vm/src/protocol/sequence.rs``
BufferMethods now Clone, Copy and gained release: fn(&PyBuffer) and retain: fn(&PyBuffer) fields; PyMappingMethods and PySequenceMethods gain Clone, Copy.
VM — stdlib / misc / examples
\crates/vm/src/stdlib/*.rs`, `crates/vm/src/anystr.rs`, `crates/vm/src/builtins/zip.rs`, `crates/wasm/src/vm_class.rs`, `examples/dis.rs``
Added Clone, Copy derives to various stdlib/public types (DumpError, TargetIsDirectory, Generic → unit-like, NoDefault, Split/Expand args, PyZipNewArgs, etc.); VMStore gained Clone, Copy; examples/dis.rs stops cloning opts in loop (uses copy).
Windows fileutils
\crates/common/src/fileutils.rs``
Added Clone, Copy to several Windows-specific stat structs and enums to allow by-value copies.

Sequence Diagram(s)

(Skipped — changes are primarily trait derives, small API additions, and minor signature tweaks that do not introduce a new multi-component sequential flow.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • youknowone
  • arihant2math

Poem

🐰
I nudged the structs, light as air,
Gave them Copy feet to skip and share.
No heavy clones, just tiny hops,
A lint gave notice — mind the props.
Now fields can flutter — hop, hop, hop!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 31.03% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'derive Copy where possible' accurately and clearly describes the main objective of the changeset—adding Copy trait derivations to multiple types across the codebase.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.