Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
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 crates/codegen/src/compile.rs
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 crates/codegen/src/error.rs
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 crates/codegen/src/ir.rs
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 crates/codegen/src/symboltable.rs
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 crates/common/src/cformat.rs
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 crates/common/src/encodings.rs
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 crates/common/src/fileutils.rs
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 crates/common/src/format.rs
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 crates/common/src/hash.rs
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 crates/common/src/int.rs
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 crates/common/src/lock/cell_lock.rs
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) }
}
}
8 changes: 6 additions & 2 deletions crates/common/src/lock/thread_mutex.rs
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 crates/common/src/str.rs
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 crates/compiler-core/src/bytecode.rs
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 crates/compiler-core/src/marshal.rs
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 crates/compiler-core/src/mode.rs
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 crates/sre_engine/src/constants.rs
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
Loading