diff --git a/Cargo.toml b/Cargo.toml index 280b64f01e5..677de28ef1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -363,6 +363,7 @@ std_instead_of_core = "warn" tests_outside_test_module = "warn" # nursery lints to enforce gradually +collection_is_never_read = "warn" debug_assert_with_mut_call = "warn" derive_partial_eq_without_eq = "warn" imprecise_flops = "warn" @@ -376,6 +377,8 @@ search_is_some = "warn" significant_drop_in_scrutinee = "warn" single_option_map = "warn" trait_duplication_in_bounds = "warn" +type_repetition_in_bounds = "warn" +unnecessary_struct_initialization = "warn" unused_peekable = "warn" unused_rounding = "warn" use_self = "warn" @@ -387,8 +390,10 @@ checked_conversions = "warn" cloned_instead_of_copied = "warn" collapsible_else_if = "warn" comparison_chain = "warn" +copy_iterator = "warn" doc_link_with_quotes = "warn" duration_suboptimal_units = "warn" +elidable_lifetime_names = "warn" enum_glob_use = "warn" explicit_deref_methods = "warn" explicit_into_iter_loop = "warn" @@ -404,6 +409,7 @@ ip_constant = "warn" iter_filter_is_ok = "warn" iter_filter_is_some = "warn" large_futures = "warn" +large_types_passed_by_value = "warn" manual_instant_elapsed = "warn" manual_is_variant_and = "warn" map_unwrap_or = "warn" @@ -421,7 +427,9 @@ range_plus_one = "warn" redundant_else = "warn" ref_option = "warn" return_self_not_must_use = "warn" +same_functions_in_if_condition = "warn" single_char_pattern = "warn" +trivially_copy_pass_by_ref = "warn" unchecked_time_subtraction = "warn" uninlined_format_args = "warn" unnecessary_box_returns = "warn" diff --git a/crates/codegen/src/compile.rs b/crates/codegen/src/compile.rs index 476aa35e3ef..45c7dce6096 100644 --- a/crates/codegen/src/compile.rs +++ b/crates/codegen/src/compile.rs @@ -2091,7 +2091,7 @@ impl Compiler { self.emit_resume_for_scope(CompilerScope::Module, 1); emit!(self, PseudoInstruction::AnnotationsPlaceholder); - let (doc, statements) = split_doc_with_range(&body.body, &self.opts); + let (doc, statements) = split_doc_with_range(&body.body, self.opts); let module_start_loc = self.module_start_location(&body.body); // Handle annotation bookkeeping before the docstring assignment, as // codegen_body() does after _PyCodegen_Module() inserts the prefix set. @@ -3075,7 +3075,7 @@ impl Compiler { } ast::Stmt::AugAssign(ast::StmtAugAssign { target, op, value, .. - }) => self.compile_augassign(target, op, value)?, + }) => self.compile_augassign(target, *op, value)?, ast::Stmt::AnnAssign(ast::StmtAnnAssign { target, annotation, @@ -4294,7 +4294,7 @@ impl Compiler { self.set_qualname(); // Handle docstring - store in co_consts[0] if present - let (doc_info, body) = split_doc_with_range(body, &self.opts); + let (doc_info, body) = split_doc_with_range(body, self.opts); let doc_str = doc_info.as_ref().map(|(doc, _)| doc); if let Some(doc) = &doc_str { // Docstring present: store in co_consts[0] and set HAS_DOCSTRING flag @@ -5137,7 +5137,7 @@ impl Compiler { self.code_stack.last_mut().unwrap().private = Some(name.to_owned()); // 2. Set up class namespace - let (doc_str, body) = split_doc_with_range(body, &self.opts); + let (doc_str, body) = split_doc_with_range(body, self.opts); let class_body_prefix_range = self.source_line_start_range(firstlineno); self.set_source_range(class_body_prefix_range); @@ -7004,7 +7004,7 @@ impl Compiler { } /// [CPython `compiler_addcompare`](https://github.com/python/cpython/blob/627894459a84be3488a1789919679c997056a03c/Python/compile.c#L2880-L2924) - fn compile_addcompare(&mut self, op: &ast::CmpOp) { + fn compile_addcompare(&mut self, op: ast::CmpOp) { match op { ast::CmpOp::Eq => emit!( self, @@ -7096,7 +7096,7 @@ impl Compiler { if mid_comparators.is_empty() { self.compile_expression(last_comparator)?; self.set_source_range(compare_range); - self.compile_addcompare(last_op); + self.compile_addcompare(*last_op); return Ok(()); } @@ -7112,7 +7112,7 @@ impl Compiler { emit!(self, Instruction::Swap { i: 2 }); emit!(self, Instruction::Copy { i: 2 }); - self.compile_addcompare(op); + self.compile_addcompare(*op); // if comparison result is false, we break with this value; if true, try the next one. emit!(self, Instruction::Copy { i: 1 }); @@ -7123,7 +7123,7 @@ impl Compiler { self.compile_expression(last_comparator)?; self.set_source_range(compare_range); - self.compile_addcompare(last_op); + self.compile_addcompare(*last_op); let end = self.new_block(); emit!(self, PseudoInstruction::JumpNoInterrupt { delta: end }); @@ -7154,7 +7154,7 @@ impl Compiler { self.compile_expression(left)?; self.compile_expression(last_comparator)?; self.set_source_range(compare_range); - self.compile_addcompare(last_op); + self.compile_addcompare(*last_op); self.emit_pop_jump_by_condition(condition, target_block); return Ok(()); } @@ -7167,14 +7167,14 @@ impl Compiler { self.set_source_range(compare_range); emit!(self, Instruction::Swap { i: 2 }); emit!(self, Instruction::Copy { i: 2 }); - self.compile_addcompare(op); + self.compile_addcompare(*op); emit!(self, Instruction::ToBool); emit!(self, Instruction::PopJumpIfFalse { delta: cleanup }); } self.compile_expression(last_comparator)?; self.set_source_range(compare_range); - self.compile_addcompare(last_op); + self.compile_addcompare(*last_op); emit!(self, Instruction::ToBool); self.emit_pop_jump_by_condition(condition, target_block); let end = self.new_block(); @@ -7446,7 +7446,7 @@ impl Compiler { fn compile_augassign( &mut self, target: &ast::Expr, - op: &ast::Operator, + op: ast::Operator, value: &ast::Expr, ) -> CompileResult<()> { let stmt_range = self.current_source_range; @@ -7559,7 +7559,7 @@ impl Compiler { Ok(()) } - fn compile_op(&mut self, op: &ast::Operator, inplace: bool) { + fn compile_op(&mut self, op: ast::Operator, inplace: bool) { let bin_op = match op { ast::Operator::Add => BinaryOperator::Add, ast::Operator::Sub => BinaryOperator::Subtract, @@ -7687,7 +7687,7 @@ impl Compiler { /// Compile a boolean operation as an expression. /// This means, that the last value remains on the stack. - fn compile_bool_op(&mut self, op: &ast::BoolOp, values: &[ast::Expr]) -> CompileResult<()> { + fn compile_bool_op(&mut self, op: ast::BoolOp, values: &[ast::Expr]) -> CompileResult<()> { let boolop_range = self.current_source_range; let after_block = self.new_block(); let (last_value, prefix_values) = values.split_last().unwrap(); @@ -7707,7 +7707,7 @@ impl Compiler { /// Emit CPython-style pseudo conditional jump for short-circuit evaluation. /// flowgraph.c lowers it to `COPY 1; TO_BOOL; POP_JUMP_IF_*`. - fn emit_short_circuit_test(&mut self, op: &ast::BoolOp, target: BlockIdx) { + fn emit_short_circuit_test(&mut self, op: ast::BoolOp, target: BlockIdx) { match op { ast::BoolOp::And => { emit!(self, PseudoInstruction::JumpIfFalse { delta: target }); @@ -7962,7 +7962,7 @@ impl Compiler { func, arguments, .. }) => self.compile_call(func, arguments)?, ast::Expr::BoolOp(ast::ExprBoolOp { op, values, .. }) => { - self.compile_bool_op(op, values)? + self.compile_bool_op(*op, values)? } ast::Expr::BinOp(ast::ExprBinOp { left, op, right, .. @@ -7972,7 +7972,7 @@ impl Compiler { // Restore full expression range before emitting the operation self.set_source_range(range); - self.compile_op(op, false); + self.compile_op(*op, false); } ast::Expr::Subscript(ast::ExprSubscript { value, slice, ctx, .. @@ -12000,10 +12000,10 @@ fn expandtabs(input: &str, tab_size: usize) -> String { expanded_str } -fn split_doc_with_range<'a>( - body: &'a [ast::Stmt], - opts: &CompileOpts, -) -> (Option<(String, TextRange)>, &'a [ast::Stmt]) { +fn split_doc_with_range( + body: &[ast::Stmt], + opts: CompileOpts, +) -> (Option<(String, TextRange)>, &[ast::Stmt]) { if let Some((ast::Stmt::Expr(expr), body_rest)) = body.split_first() { let doc_comment = match &*expr.value { ast::Expr::StringLiteral(value) => Some((&value.value, expr.value.range())), @@ -12023,7 +12023,7 @@ fn split_doc_with_range<'a>( } #[cfg(test)] -fn split_doc<'a>(body: &'a [ast::Stmt], opts: &CompileOpts) -> (Option, &'a [ast::Stmt]) { +fn split_doc(body: &[ast::Stmt], opts: CompileOpts) -> (Option, &[ast::Stmt]) { let (doc, body) = split_doc_with_range(body, opts); (doc.map(|(doc, _)| doc), body) } @@ -12452,7 +12452,7 @@ def f(x, y, z): in_async_scope: is_async, }; compiler.set_qualname(); - let (_doc_str, body) = split_doc(body, &compiler.opts); + let (_doc_str, body) = split_doc(body, compiler.opts); let start_label = compiler.use_cpython_function_start_label(); let is_gen = is_async || compiler.current_symbol_table().is_generator; let stop_iteration_block = if is_gen { diff --git a/crates/codegen/src/ir.rs b/crates/codegen/src/ir.rs index f22efe8e52d..74f55868867 100644 --- a/crates/codegen/src/ir.rs +++ b/crates/codegen/src/ir.rs @@ -3291,9 +3291,9 @@ fn optimize_lists_and_sets( const VISITED: i32 = -1; /// flowgraph.c SWAPPABLE -fn is_swappable(instr: &AnyInstruction) -> bool { +fn is_swappable(instr: AnyInstruction) -> bool { matches!( - (*instr).into(), + instr.into(), AnyOpcode::Real(Opcode::StoreFast | Opcode::PopTop) | AnyOpcode::Pseudo(PseudoOpcode::StoreFastMaybeNull) ) @@ -3315,17 +3315,22 @@ fn next_swappable_instruction(block: &Block, mut i: usize, lineno: i32) -> Optio if i >= block.instruction_used { return None; } + let info = &block.instructions[i]; let info_lineno = instruction_lineno(info); + if lineno >= 0 && info_lineno != lineno { return None; } + if matches!(info.instr, AnyInstruction::Real(Instruction::Nop)) { continue; } - if is_swappable(&info.instr) { + + if is_swappable(info.instr) { return Some(i); } + return None; } } @@ -5440,7 +5445,7 @@ fn basicblock_add_jump( } /// pycore_opcode_utils.h IS_CONDITIONAL_JUMP_OPCODE -fn is_conditional_jump_opcode(instr: &AnyInstruction) -> bool { +fn is_conditional_jump_opcode(instr: AnyInstruction) -> bool { matches!( instr.real().map(Into::into), Some( @@ -5524,7 +5529,7 @@ fn normalize_jumps_in_block( let Some(last_ins) = basicblock_last_instr(&blocks[idx]).copied() else { return Ok(()); }; - if !is_conditional_jump_opcode(&last_ins.instr) { + if !is_conditional_jump_opcode(last_ins.instr) { return Ok(()); } debug_assert!(!last_ins.instr.is_assembler()); diff --git a/crates/common/src/format.rs b/crates/common/src/format.rs index ea459886914..5510dce41d0 100644 --- a/crates/common/src/format.rs +++ b/crates/common/src/format.rs @@ -141,8 +141,8 @@ impl FormatParse for FormatGrouping { } } -impl From<&FormatGrouping> for char { - fn from(fg: &FormatGrouping) -> Self { +impl From for char { + fn from(fg: FormatGrouping) -> Self { match fg { FormatGrouping::Comma => ',', FormatGrouping::Underscore => '_', @@ -150,6 +150,12 @@ impl From<&FormatGrouping> for char { } } +impl From<&FormatGrouping> for char { + fn from(fg: &FormatGrouping) -> Self { + Self::from(*fg) + } +} + #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum FormatType { String, @@ -322,7 +328,7 @@ impl FormatSpec { return Err(FormatSpecError::DecimalDigitsTooMany); } let (grouping_option, text) = FormatGrouping::parse(text); - if let Some(grouping) = &grouping_option { + if let Some(grouping) = grouping_option { Self::validate_separator(grouping, text)?; } let (precision, text) = parse_precision(text)?; @@ -349,11 +355,12 @@ impl FormatSpec { }) } - fn validate_separator(grouping: &FormatGrouping, text: &Wtf8) -> Result<(), FormatSpecError> { + fn validate_separator(grouping: FormatGrouping, text: &Wtf8) -> Result<(), FormatSpecError> { let mut chars = text.code_points().peekable(); + let grouping_char = char::from(grouping); match chars.peek().and_then(|cp| CodePoint::to_char(*cp)) { Some(c) if c == ',' || c == '_' => { - if c == char::from(grouping) { + if c == grouping_char { Err(FormatSpecError::UnspecifiedFormat(c, c)) } else { Err(FormatSpecError::ExclusiveFormat(',', '_')) diff --git a/crates/host_env/src/crt_fd.rs b/crates/host_env/src/crt_fd.rs index c49d661b37a..ee21934bee2 100644 --- a/crates/host_env/src/crt_fd.rs +++ b/crates/host_env/src/crt_fd.rs @@ -112,7 +112,7 @@ mod win { } #[inline] - pub(super) fn as_raw_fd(&self) -> Raw { + pub(super) fn as_raw_fd(self) -> Raw { self.fd } } @@ -140,12 +140,13 @@ pub struct Borrowed<'fd> { inner: BorrowedInner<'fd>, } -impl<'fd> PartialEq for Borrowed<'fd> { +impl PartialEq for Borrowed<'_> { fn eq(&self, other: &Self) -> bool { self.as_raw() == other.as_raw() } } -impl<'fd> Eq for Borrowed<'fd> {} + +impl Eq for Borrowed<'_> {} impl fmt::Debug for Borrowed<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -250,7 +251,7 @@ impl IntoRawFd for Owned { } } -impl<'fd> Borrowed<'fd> { +impl Borrowed<'_> { /// Create a `crt_fd::Borrowed` from a raw file descriptor. /// /// # Safety diff --git a/crates/host_env/src/fileutils.rs b/crates/host_env/src/fileutils.rs index 79cee1cb551..c9e366e3dd5 100644 --- a/crates/host_env/src/fileutils.rs +++ b/crates/host_env/src/fileutils.rs @@ -165,8 +165,8 @@ pub mod windows { (time_out, nsec_out as _) } - fn file_time_to_time_t_nsec(in_ptr: &FILETIME) -> (libc::time_t, libc::c_int) { - let in_val: i64 = unsafe { core::mem::transmute_copy(in_ptr) }; + fn file_time_to_time_t_nsec(in_ptr: FILETIME) -> (libc::time_t, libc::c_int) { + let in_val: i64 = unsafe { core::mem::transmute_copy(&in_ptr) }; let nsec_out = (in_val % 10_000_000) * 100; // FILETIME is in units of 100 nsec. let time_out = (in_val / 10_000_000) - SECS_BETWEEN_EPOCHS; (time_out, nsec_out as _) @@ -196,10 +196,10 @@ pub mod windows { ) } else { ( - file_time_to_time_t_nsec(&info.ftCreationTime), + file_time_to_time_t_nsec(info.ftCreationTime), (0, 0), - file_time_to_time_t_nsec(&info.ftLastWriteTime), - file_time_to_time_t_nsec(&info.ftLastAccessTime), + file_time_to_time_t_nsec(info.ftLastWriteTime), + file_time_to_time_t_nsec(info.ftLastAccessTime), ) }; let st_nlink = info.nNumberOfLinks as i32; diff --git a/crates/host_env/src/signal.rs b/crates/host_env/src/signal.rs index ab1974f37df..cd11998e5ff 100644 --- a/crates/host_env/src/signal.rs +++ b/crates/host_env/src/signal.rs @@ -327,8 +327,8 @@ pub fn valid_signals(max_signum: usize) -> io::Result> { } #[cfg(unix)] -pub fn sigset_contains(mask: &libc::sigset_t, signum: i32) -> bool { - unsafe { libc::sigismember(mask, signum) == 1 } +pub fn sigset_contains(mask: libc::sigset_t, signum: i32) -> bool { + unsafe { libc::sigismember(&mask, signum) == 1 } } #[cfg(windows)] diff --git a/crates/stdlib/src/_asyncio.rs b/crates/stdlib/src/_asyncio.rs index 48be4115ed6..0c74310eaef 100644 --- a/crates/stdlib/src/_asyncio.rs +++ b/crates/stdlib/src/_asyncio.rs @@ -101,7 +101,7 @@ pub(crate) mod _asyncio { } impl FutureState { - fn as_str(&self) -> &'static str { + const fn as_str(self) -> &'static str { match self { Self::Pending => "PENDING", Self::Cancelled => "CANCELLED", diff --git a/crates/stdlib/src/binascii.rs b/crates/stdlib/src/binascii.rs index 30e9b379ad9..ac945235884 100644 --- a/crates/stdlib/src/binascii.rs +++ b/crates/stdlib/src/binascii.rs @@ -386,18 +386,18 @@ mod decl { } #[inline] - fn uu_a2b_read(c: &u8, vm: &VirtualMachine) -> PyResult { + fn uu_a2b_read(c: u8, vm: &VirtualMachine) -> PyResult { // Check the character for legality // The 64 instead of the expected 63 is because // there are a few uuencodes out there that use // '`' as zero instead of space. - if !(b' '..=(b' ' + 64)).contains(c) { - if [b'\r', b'\n'].contains(c) { + if !(b' '..=(b' ' + 64)).contains(&c) { + if [b'\r', b'\n'].contains(&c) { return Ok(0); } return Err(super::new_binascii_error("Illegal char", vm)); } - Ok((*c - b' ') & 0x3f) + Ok((c - b' ') & 0x3f) } #[derive(FromArgs)] @@ -407,6 +407,7 @@ mod decl { #[pyarg(named, default = false)] header: bool, } + #[pyfunction] fn a2b_qp(args: A2bQpArgs) -> PyResult> { let s = args.data; @@ -760,7 +761,7 @@ mod decl { let (char_a, char_b, char_c, char_d) = { let mut chunk = chunk .iter() - .map(|x| uu_a2b_read(x, vm)) + .map(|&x| uu_a2b_read(x, vm)) .collect::, _>>()?; while chunk.len() < 4 { chunk.push(0); diff --git a/crates/stdlib/src/ssl.rs b/crates/stdlib/src/ssl.rs index 35cb1794045..edcdf18fa09 100644 --- a/crates/stdlib/src/ssl.rs +++ b/crates/stdlib/src/ssl.rs @@ -461,7 +461,7 @@ mod _ssl { // Generate a synthetic session ID from server name and timestamp // NOTE: This is NOT the actual TLS session ID, just a unique identifier - fn generate_session_id_from_metadata(server_name: &str, time: &SystemTime) -> Vec { + fn generate_session_id_from_metadata(server_name: &str, time: SystemTime) -> Vec { let mut hasher = Sha256::new(); hasher.update(server_name.as_bytes()); hasher.update( @@ -507,7 +507,7 @@ mod _ssl { _server_name: server_name_str.as_ref().to_string(), session_id: generate_session_id_from_metadata( server_name_str.as_ref(), - &creation_time, + creation_time, ), creation_time, lifetime: 7200, // TLS 1.2 default session lifetime @@ -551,7 +551,7 @@ mod _ssl { _server_name: server_name_str.to_string(), session_id: generate_session_id_from_metadata( server_name_str.as_ref(), - &creation_time, + creation_time, ), creation_time, lifetime: 7200, // Default TLS 1.3 ticket lifetime (Rustls uses this) @@ -2501,7 +2501,7 @@ mod _ssl { } else { // Create new session ID if not in cache let time = std::time::SystemTime::now(); - (generate_session_id_from_metadata(name, &time), time, 7200) + (generate_session_id_from_metadata(name, time), time, 7200) } } else { // No server name, use defaults diff --git a/crates/vm/src/builtins/float.rs b/crates/vm/src/builtins/float.rs index db6478d668d..85627fd7332 100644 --- a/crates/vm/src/builtins/float.rs +++ b/crates/vm/src/builtins/float.rs @@ -254,6 +254,10 @@ fn float_from_string(val: PyObjectRef, vm: &VirtualMachine) -> PyResult { }) } +#[expect( + clippy::trivially_copy_pass_by_ref, + reason = "Needs to comply with a signature" +)] #[pyclass( flags(BASETYPE, _MATCH_SELF), with(Comparable, Hashable, Constructor, AsNumber, Representable) diff --git a/crates/vm/src/builtins/type.rs b/crates/vm/src/builtins/type.rs index d26c81a7b76..89321189b09 100644 --- a/crates/vm/src/builtins/type.rs +++ b/crates/vm/src/builtins/type.rs @@ -370,7 +370,7 @@ unsafe impl Sync for PointerSlot {} unsafe impl Send for PointerSlot {} impl PointerSlot { - pub(crate) const unsafe fn borrow_static(&self) -> &'static T { + pub(crate) const unsafe fn borrow_static(self) -> &'static T { unsafe { self.0.as_ref() } } } diff --git a/crates/vm/src/protocol/callable.rs b/crates/vm/src/protocol/callable.rs index 42d0ac194ae..c9afbd5afb0 100644 --- a/crates/vm/src/protocol/callable.rs +++ b/crates/vm/src/protocol/callable.rs @@ -151,7 +151,7 @@ pub(crate) enum TraceEvent { impl TraceEvent { /// Whether sys.settrace receives this event. #[must_use] - const fn is_trace_event(&self) -> bool { + const fn is_trace_event(self) -> bool { matches!( self, Self::Call | Self::Return | Self::Exception | Self::Line | Self::Opcode @@ -162,7 +162,7 @@ impl TraceEvent { /// In legacy_tracing.c, profile callbacks are only registered for /// PY_RETURN, PY_UNWIND, C_CALL, C_RETURN, C_RAISE. #[must_use] - const fn is_profile_event(&self) -> bool { + const fn is_profile_event(self) -> bool { matches!( self, Self::Call | Self::Return | Self::CCall | Self::CReturn | Self::CException @@ -171,7 +171,7 @@ impl TraceEvent { /// Whether this event is dispatched only when f_trace_opcodes is set. #[must_use] - pub(crate) const fn is_opcode_event(&self) -> bool { + pub(crate) const fn is_opcode_event(self) -> bool { matches!(self, Self::Opcode) } } diff --git a/crates/vm/src/protocol/number.rs b/crates/vm/src/protocol/number.rs index 86b126538ca..301499aa115 100644 --- a/crates/vm/src/protocol/number.rs +++ b/crates/vm/src/protocol/number.rs @@ -631,18 +631,6 @@ impl Deref for PyNumber<'_> { } } -impl<'a> PyNumber<'a> { - // PyNumber_Check - slots are now inherited - #[must_use] - pub fn check(obj: &PyObject) -> bool { - let methods = &obj.class().slots.as_number; - let has_number = methods.int.load().is_some() - || methods.index.load().is_some() - || methods.float.load().is_some(); - has_number || obj.downcastable::() - } -} - impl PyNumber<'_> { // PyIndex_Check #[must_use] @@ -736,6 +724,16 @@ and may be removed in a future version of Python." } }) } + + // PyNumber_Check - slots are now inherited + #[must_use] + pub fn check(obj: &PyObject) -> bool { + let methods = &obj.class().slots.as_number; + let has_number = methods.int.load().is_some() + || methods.index.load().is_some() + || methods.float.load().is_some(); + has_number || obj.downcastable::() + } } pub fn handle_bytes_to_int_err( diff --git a/crates/vm/src/protocol/sequence.rs b/crates/vm/src/protocol/sequence.rs index dbef92c66a9..774e579ee62 100644 --- a/crates/vm/src/protocol/sequence.rs +++ b/crates/vm/src/protocol/sequence.rs @@ -286,7 +286,7 @@ impl PySequence<'_> { } fn _ass_slice( - &self, + self, start: isize, stop: isize, value: Option, diff --git a/crates/vm/src/stdlib/_ast.rs b/crates/vm/src/stdlib/_ast.rs index 38e0d546f44..6bbbbefe504 100644 --- a/crates/vm/src/stdlib/_ast.rs +++ b/crates/vm/src/stdlib/_ast.rs @@ -720,11 +720,12 @@ fn fold_expr(expr: &mut ast::Expr) { let Expr::NumberLiteral(left) = binop.left.as_ref() else { return; }; + let Expr::NumberLiteral(right) = binop.right.as_ref() else { return; }; - if let Some(number) = fold_number_binop(&left.value, &binop.op, &right.value) { + if let Some(number) = fold_number_binop(&left.value, binop.op, &right.value) { *expr = Expr::NumberLiteral(ast::ExprNumberLiteral { node_index: binop.node_index.clone(), range: binop.range, @@ -737,7 +738,7 @@ fn fold_expr(expr: &mut ast::Expr) { #[cfg(feature = "parser")] fn fold_number_binop( left: &ast::Number, - op: &ast::Operator, + op: ast::Operator, right: &ast::Number, ) -> Option { let (left_real, left_imag, left_is_complex) = number_to_complex(left)?; diff --git a/crates/vm/src/stdlib/_io.rs b/crates/vm/src/stdlib/_io.rs index 423d5bc676f..719355ec3b3 100644 --- a/crates/vm/src/stdlib/_io.rs +++ b/crates/vm/src/stdlib/_io.rs @@ -2310,7 +2310,7 @@ mod _io { impl Newlines { /// returns position where the new line starts if found, otherwise position at which to /// continue the search after more is read into the buffer - fn find_newline(&self, s: &Wtf8) -> Result { + fn find_newline(self, s: &Wtf8) -> Result { let len = s.len(); match self { Self::Universal | Self::Lf => s.find("\n".as_ref()).map(|p| p + 1).ok_or(len), diff --git a/crates/vm/src/stdlib/_signal.rs b/crates/vm/src/stdlib/_signal.rs index e3d12568d26..71063d8959b 100644 --- a/crates/vm/src/stdlib/_signal.rs +++ b/crates/vm/src/stdlib/_signal.rs @@ -442,7 +442,7 @@ pub(crate) mod _signal { } #[cfg(unix)] - fn sigset_to_pyset(mask: &libc::sigset_t, vm: &VirtualMachine) -> PyResult { + fn sigset_to_pyset(mask: libc::sigset_t, vm: &VirtualMachine) -> PyResult { use crate::PyPayload; use crate::builtins::PySet; let set = PySet::default().into_ref(&vm.ctx); @@ -491,7 +491,7 @@ pub(crate) mod _signal { signal::check_signals(vm)?; // Convert old mask to Python set - sigset_to_pyset(&old_mask, vm) + sigset_to_pyset(old_mask, vm) } #[cfg(any(unix, windows))] diff --git a/crates/vm/src/types/slot.rs b/crates/vm/src/types/slot.rs index a56d1c493f9..4197e1554aa 100644 --- a/crates/vm/src/types/slot.rs +++ b/crates/vm/src/types/slot.rs @@ -202,10 +202,13 @@ impl PyTypeSlots { #[must_use] pub fn heap_default() -> Self { + /* Self { - // init: AtomicCell::new(Some(init_wrapper)), + init: AtomicCell::new(Some(init_wrapper)), ..Default::default() } + */ + Self::default() } } @@ -663,7 +666,7 @@ impl PyType { // NOTE: Collect into Vec first to avoid issues during iteration let defs: Vec<_> = find_slot_defs_by_name(name.as_str()).collect(); for def in defs { - self.update_one_slot::(&def.accessor, name, ctx); + self.update_one_slot::(def.accessor, name, ctx); } // Recursively update subclasses that don't have their own definition @@ -689,7 +692,7 @@ impl PyType { // Update subclass's slots for def in find_slot_defs_by_name(name.as_str()) { - subclass.update_one_slot::(&def.accessor, name, ctx); + subclass.update_one_slot::(def.accessor, name, ctx); } // Recurse into subclass's subclasses @@ -700,7 +703,7 @@ impl PyType { /// Update a single slot fn update_one_slot( &self, - accessor: &SlotAccessor, + accessor: SlotAccessor, name: &'static PyStrInterned, ctx: &Context, ) { diff --git a/crates/vm/src/vm/thread.rs b/crates/vm/src/vm/thread.rs index 33fcec5e43e..26d8db9d764 100644 --- a/crates/vm/src/vm/thread.rs +++ b/crates/vm/src/vm/thread.rs @@ -671,8 +671,7 @@ impl VirtualMachine { #[cfg(feature = "threading")] pub fn start_thread(&self, f: F) -> std::thread::JoinHandle where - F: FnOnce(&Self) -> R, - F: Send + 'static, + F: Send + 'static + FnOnce(&Self) -> R, R: Send + 'static, { let func = self.new_thread().make_spawn_func(f); diff --git a/crates/vm/src/vm/vm_new.rs b/crates/vm/src/vm/vm_new.rs index 30b8e6b1af0..4db965855df 100644 --- a/crates/vm/src/vm/vm_new.rs +++ b/crates/vm/src/vm/vm_new.rs @@ -65,8 +65,8 @@ impl SyntaxErrorInfo { #[cfg(feature = "parser")] #[must_use] - const fn handle_expected_token(expected: &TokenKind, found: &TokenKind) -> &'static str { - match (*expected, *found) { + const fn handle_expected_token(expected: TokenKind, found: TokenKind) -> &'static str { + match (expected, found) { (TokenKind::Colon, TokenKind::Newline) => "expected ':'", (TokenKind::Lpar, _) => "expected '('", @@ -110,7 +110,7 @@ impl SyntaxErrorInfo { ParseErrorType::UnexpectedExpressionToken => format!("invalid syntax: {}", self.msg), ParseErrorType::ExpectedToken { expected, found } => { - Self::handle_expected_token(expected, found).into() + Self::handle_expected_token(*expected, *found).into() } ParseErrorType::InvalidStarredExpressionUsage => {