GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — derive `Copy` where possible by ShaharNaveh · Pull Request #6844 · RustPython/RustPython

derive Copy where possible #6844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
youknowone merged 3 commits into RustPython:main from ShaharNaveh:codegen-blocks-copy
Jan 23, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

derive Copy where possible #6844

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
2f76ef6
Add workspace lint
ShaharNaveh Jan 23, 2026
a9364cb
Fix warnings
ShaharNaveh Jan 23, 2026
2c2b137
Clippy
ShaharNaveh Jan 23, 2026
File filter
Filter by extension


Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

1 change: 1 addition & 0 deletions 1 Cargo.toml
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ wasm-bindgen = "0.2.106"
unsafe_code = "allow"
unsafe_op_in_unsafe_fn = "deny"
elided_lifetimes_in_paths = "warn"
missing_copy_implementations = "warn"

[workspace.lints.clippy]
# alloc_instead_of_core = "warn"
Expand Down
3 changes: 2 additions & 1 deletion 3 crates/codegen/src/compile.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ struct Compiler {
in_annotation: bool,
}

#[derive(Clone, Copy)]
enum DoneWithFuture {
No,
DoneWithDoc,
Yes,
}

#[derive(Debug, Clone)]
#[derive(Clone, Copy, Debug)]
pub struct CompileOpts {
/// How optimized the bytecode output should be; any optimize > 0 does
/// not emit assert statements
Expand Down
2 changes: 1 addition & 1 deletion 2 crates/codegen/src/error.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::fmt::Display;
use rustpython_compiler_core::SourceLocation;
use thiserror::Error;

#[derive(Debug)]
#[derive(Clone, Copy, Debug)]
pub enum PatternUnreachableReason {
NameCapture,
Wildcard,
Expand Down
12 changes: 6 additions & 6 deletions 12 crates/codegen/src/ir.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl ops::IndexMut<BlockIdx> for Vec<Block> {
}
}

#[derive(Debug, Clone)]
#[derive(Clone, Copy, Debug)]
pub struct InstructionInfo {
pub instr: AnyInstruction,
pub arg: OpArg,
Expand All @@ -95,8 +95,8 @@ pub struct InstructionInfo {
pub except_handler: Option<ExceptHandlerInfo>,
}

/// Exception handler information for an instruction
#[derive(Debug, Clone)]
/// Exception handler information for an instruction.
#[derive(Clone, Copy, Debug)]
pub struct ExceptHandlerInfo {
/// Block to jump to when exception occurs
pub handler_block: BlockIdx,
Expand Down Expand Up @@ -742,13 +742,13 @@ fn generate_exception_table(blocks: &[Block], block_to_index: &[u32]) -> Box<[u8
// instr_size includes EXTENDED_ARG instructions
let instr_size = instr.arg.instr_size() as u32;

match (&current_entry, &instr.except_handler) {
match (&current_entry, instr.except_handler) {
// No current entry, no handler - nothing to do
(None, None) => {}

// No current entry, handler starts - begin new entry
(None, Some(handler)) => {
current_entry = Some((handler.clone(), instr_index));
current_entry = Some((handler, instr_index));
}

// Current entry exists, same handler - continue
Expand All @@ -767,7 +767,7 @@ fn generate_exception_table(blocks: &[Block], block_to_index: &[u32]) -> Box<[u8
curr_handler.stack_depth as u16,
curr_handler.preserve_lasti,
));
current_entry = Some((handler.clone(), instr_index));
current_entry = Some((handler, instr_index));
}

// Current entry exists, no handler - finish current entry
Expand Down
2 changes: 1 addition & 1 deletion 2 crates/codegen/src/symboltable.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ impl SymbolTableAnalyzer {
}
}

#[derive(Debug, Clone)]
#[derive(Clone, Copy, Debug)]
enum SymbolUsage {
Global,
Nonlocal,
Expand Down
4 changes: 2 additions & 2 deletions 4 crates/common/src/cformat.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustpython_literal::{float, format::Case};

use crate::wtf8::{CodePoint, Wtf8, Wtf8Buf};

#[derive(Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum CFormatErrorType {
UnmatchedKeyParentheses,
MissingModuloSign,
Expand All @@ -27,7 +27,7 @@ pub enum CFormatErrorType {
// also contains how many chars the parsing function consumed
pub type ParsingError = (CFormatErrorType, usize);

#[derive(Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct CFormatError {
pub typ: CFormatErrorType, // FIXME
pub index: usize,
Expand Down
7 changes: 7 additions & 0 deletions 7 crates/common/src/encodings.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ pub mod errors {
use super::*;
use core::fmt::Write;

#[derive(Clone, Copy)]
pub struct Strict;

impl<Ctx: EncodeContext> EncodeErrorHandler<Ctx> for Strict {
Expand All @@ -286,6 +287,7 @@ pub mod errors {
}
}

#[derive(Clone, Copy)]
pub struct Ignore;

impl<Ctx: EncodeContext> EncodeErrorHandler<Ctx> for Ignore {
Expand All @@ -310,6 +312,7 @@ pub mod errors {
}
}

#[derive(Clone, Copy)]
pub struct Replace;

impl<Ctx: EncodeContext> EncodeErrorHandler<Ctx> for Replace {
Expand Down Expand Up @@ -338,6 +341,7 @@ pub mod errors {
}
}

#[derive(Clone, Copy)]
pub struct XmlCharRefReplace;

impl<Ctx: EncodeContext> EncodeErrorHandler<Ctx> for XmlCharRefReplace {
Expand All @@ -358,6 +362,7 @@ pub mod errors {
}
}

#[derive(Clone, Copy)]
pub struct BackslashReplace;

impl<Ctx: EncodeContext> EncodeErrorHandler<Ctx> for BackslashReplace {
Expand Down Expand Up @@ -394,6 +399,7 @@ pub mod errors {
}
}

#[derive(Clone, Copy)]
pub struct NameReplace;

impl<Ctx: EncodeContext> EncodeErrorHandler<Ctx> for NameReplace {
Expand Down Expand Up @@ -422,6 +428,7 @@ pub mod errors {
}
}

#[derive(Clone, Copy)]
pub struct SurrogateEscape;

impl<Ctx: EncodeContext> EncodeErrorHandler<Ctx> for SurrogateEscape {
Expand Down
6 changes: 4 additions & 2 deletions 6 crates/common/src/fileutils.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub mod windows {

pub const SECS_BETWEEN_EPOCHS: i64 = 11644473600; // Seconds between 1.1.1601 and 1.1.1970

#[derive(Default)]
#[derive(Clone, Copy, Default)]
pub struct StatStruct {
pub st_dev: libc::c_ulong,
pub st_ino: u64,
Expand Down Expand Up @@ -256,6 +256,7 @@ pub mod windows {
m as _
}

#[derive(Clone, Copy)]
#[repr(C)]
pub struct FILE_STAT_BASIC_INFORMATION {
pub FileId: i64,
Expand All @@ -275,8 +276,9 @@ pub mod windows {
pub FileId128: [u64; 2],
}

#[repr(C)]
#[allow(dead_code)]
#[derive(Clone, Copy)]
#[repr(C)]
pub enum FILE_INFO_BY_NAME_CLASS {
FileStatByNameInfo,
FileStatLxByNameInfo,
Expand Down
10 changes: 5 additions & 5 deletions 10 crates/common/src/format.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl FormatParse for FormatSign {
}
}

#[derive(Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum FormatGrouping {
Comma,
Underscore,
Expand All @@ -136,7 +136,7 @@ impl From<&FormatGrouping> for char {
}
}

#[derive(Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum FormatType {
String,
Binary,
Expand Down Expand Up @@ -199,7 +199,7 @@ impl FormatParse for FormatType {
}
}

#[derive(Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct FormatSpec {
conversion: Option<FormatConversion>,
fill: Option<CodePoint>,
Expand Down Expand Up @@ -845,7 +845,7 @@ impl Deref for AsciiStr<'_> {
}
}

#[derive(Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum FormatSpecError {
DecimalDigitsTooMany,
PrecisionTooBig,
Expand All @@ -862,7 +862,7 @@ pub enum FormatSpecError {
NotImplemented(char, &'static str),
}

#[derive(Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum FormatParseError {
UnmatchedBracket,
MissingStartBracket,
Expand Down
1 change: 1 addition & 0 deletions 1 crates/common/src/hash.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub const SEED_BITS: usize = core::mem::size_of::<u64>() * 2 * 8;

// pub const CUTOFF: usize = 7;

#[derive(Clone, Copy)]
pub struct HashSecret {
k0: u64,
k1: u64,
Expand Down
2 changes: 1 addition & 1 deletion 2 crates/common/src/int.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn float_to_ratio(value: f64) -> Option<(BigInt, BigInt)> {
})
}

#[derive(Debug, Eq, PartialEq)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum BytesToIntError {
InvalidLiteral { base: u32 },
InvalidBase,
Expand Down
6 changes: 5 additions & 1 deletion 6 crates/common/src/lock/cell_lock.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,14 @@ fn deadlock(lock_kind: &str, ty: &str) -> ! {
panic!("deadlock: tried to {lock_kind}lock a Cell{ty} twice")
}

#[derive(Clone, Copy)]
pub struct SingleThreadId(());

unsafe impl GetThreadId for SingleThreadId {
const INIT: Self = Self(());

fn nonzero_thread_id(&self) -> NonZero<usize> {
NonZero::new(1).unwrap()
// Safety: This is constant.
unsafe { NonZero::new_unchecked(1) }
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

}
}
8 changes: 6 additions & 2 deletions 8 crates/common/src/lock/thread_mutex.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,23 @@ impl<R: RawMutex, G: GetThreadId, T: ?Sized> ThreadMutex<R, G, T> {
}
}
}
// Whether ThreadMutex::try_lock failed because the mutex was already locked on another thread or
// on the current thread

#[derive(Clone, Copy)]
pub enum TryLockThreadError {
/// Failed to lock because mutex was already locked on another thread.
Other,
/// Failed to lock because mutex was already locked on current thread.
Current,
}

struct LockedPlaceholder(&'static str);

impl fmt::Debug for LockedPlaceholder {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.0)
}
}

impl<R: RawMutex, G: GetThreadId, T: ?Sized + fmt::Debug> fmt::Debug for ThreadMutex<R, G, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.try_lock() {
Expand Down
1 change: 1 addition & 0 deletions 1 crates/common/src/str.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ pub fn to_ascii(value: &str) -> AsciiString {
unsafe { AsciiString::from_ascii_unchecked(ascii) }
}

#[derive(Clone, Copy)]
pub struct UnicodeEscapeCodepoint(pub CodePoint);

impl fmt::Display for UnicodeEscapeCodepoint {
Expand Down
4 changes: 2 additions & 2 deletions 4 crates/compiler-core/src/bytecode.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod oparg;

/// Exception table entry for zero-cost exception handling
/// Format: (start, size, target, depth<<1|lasti)
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ExceptionTableEntry {
/// Start instruction offset (inclusive)
pub start: u32,
Expand All @@ -47,7 +47,7 @@ pub struct ExceptionTableEntry {
}

impl ExceptionTableEntry {
pub fn new(start: u32, end: u32, target: u32, depth: u16, push_lasti: bool) -> Self {
pub const fn new(start: u32, end: u32, target: u32, depth: u16, push_lasti: bool) -> Self {
Self {
start,
end,
Expand Down
3 changes: 2 additions & 1 deletion 3 crates/compiler-core/src/marshal.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustpython_wtf8::Wtf8;

pub const FORMAT_VERSION: u32 = 5;

#[derive(Debug)]
#[derive(Clone, Copy, Debug)]
pub enum MarshalError {
/// Unexpected End Of File
Eof,
Expand Down Expand Up @@ -42,6 +42,7 @@ impl core::error::Error for MarshalError {}

type Result<T, E = MarshalError> = core::result::Result<T, E>;

#[derive(Clone, Copy)]
#[repr(u8)]
enum Type {
// Null = b'0',
Expand Down
2 changes: 1 addition & 1 deletion 2 crates/compiler-core/src/mode.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl core::str::FromStr for Mode {
}

/// Returned when a given mode is not valid.
#[derive(Debug)]
#[derive(Clone, Copy, Debug)]
pub struct ModeParseError;

impl core::fmt::Display for ModeParseError {
Expand Down
14 changes: 8 additions & 6 deletions 14 crates/sre_engine/src/constants.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
use bitflags::bitflags;

pub const SRE_MAGIC: usize = 20230612;
#[derive(num_enum::TryFromPrimitive, Debug, PartialEq, Eq)]
#[repr(u32)]

#[allow(non_camel_case_types, clippy::upper_case_acronyms)]
#[derive(num_enum::TryFromPrimitive, Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)]
pub enum SreOpcode {
FAILURE = 0,
SUCCESS = 1,
Expand Down Expand Up @@ -63,9 +64,9 @@ pub enum SreOpcode {
RANGE_UNI_IGNORE = 42,
}

#[derive(num_enum::TryFromPrimitive, Debug, PartialEq, Eq)]
#[repr(u32)]
#[allow(non_camel_case_types, clippy::upper_case_acronyms)]
#[derive(num_enum::TryFromPrimitive, Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u32)]
pub enum SreAtCode {
BEGINNING = 0,
BEGINNING_LINE = 1,
Expand All @@ -81,9 +82,9 @@ pub enum SreAtCode {
UNI_NON_BOUNDARY = 11,
}

#[derive(num_enum::TryFromPrimitive, Debug)]
#[repr(u32)]
#[allow(non_camel_case_types, clippy::upper_case_acronyms)]
#[derive(num_enum::TryFromPrimitive, Clone, Copy, Debug)]
#[repr(u32)]
pub enum SreCatCode {
DIGIT = 0,
NOT_DIGIT = 1,
Expand Down Expand Up @@ -120,6 +121,7 @@ bitflags! {
}

bitflags! {
#[derive(Clone, Copy)]
pub struct SreInfo: u32 {
const PREFIX = 1;
const LITERAL = 2;
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.