Skip to content
Open
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
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
flamescope = { version = "0.1.2", optional = true }

rustls = { workspace = true, optional = true }
rustls-graviola = { workspace = true, optional = true }

Check warning on line 52 in Cargo.toml

View workflow job for this annotation

GitHub Actions / cargo shear

shear/misplaced_optional_dependency

misplaced optional dependency `rustls-graviola` (remove the `optional` flag and move to `[dev-dependencies]`)

[target.'cfg(windows)'.dependencies]
libc = { workspace = true }
Expand Down Expand Up @@ -363,6 +363,7 @@
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"
Expand All @@ -376,6 +377,8 @@
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"
Expand All @@ -387,8 +390,10 @@
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"
Expand All @@ -404,6 +409,7 @@
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"
Expand All @@ -421,7 +427,9 @@
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"
Expand Down
46 changes: 23 additions & 23 deletions crates/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(());
}
Expand All @@ -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 });
Expand All @@ -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 });
Expand Down Expand Up @@ -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(());
}
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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 });
Expand Down Expand Up @@ -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, ..
Expand All @@ -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, ..
Expand Down Expand Up @@ -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())),
Expand All @@ -12023,7 +12023,7 @@ fn split_doc_with_range<'a>(
}

#[cfg(test)]
fn split_doc<'a>(body: &'a [ast::Stmt], opts: &CompileOpts) -> (Option<String>, &'a [ast::Stmt]) {
fn split_doc(body: &[ast::Stmt], opts: CompileOpts) -> (Option<String>, &[ast::Stmt]) {
let (doc, body) = split_doc_with_range(body, opts);
(doc.map(|(doc, _)| doc), body)
}
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 10 additions & 5 deletions crates/codegen/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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());
Expand Down
17 changes: 12 additions & 5 deletions crates/common/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,21 @@ impl FormatParse for FormatGrouping {
}
}

impl From<&FormatGrouping> for char {
fn from(fg: &FormatGrouping) -> Self {
impl From<FormatGrouping> for char {
fn from(fg: FormatGrouping) -> Self {
match fg {
FormatGrouping::Comma => ',',
FormatGrouping::Underscore => '_',
}
}
}

impl From<&FormatGrouping> for char {
fn from(fg: &FormatGrouping) -> Self {
Self::from(*fg)
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FormatType {
String,
Expand Down Expand Up @@ -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)?;
Expand All @@ -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(',', '_'))
Expand Down
9 changes: 5 additions & 4 deletions crates/host_env/src/crt_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions crates/host_env/src/fileutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _)
Expand Down Expand Up @@ -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;
Expand Down
Loading
Loading