FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

More clippy rules (#8127) · RustPython/RustPython@9f2c4e1 · GitHub

Repository navigation

Commit 9f2c4e1

Browse files
authored
More clippy rules (#8127)
* clippy `elidable_lifetime_names` * large_types_passed_by_value * trivially_copy_pass_by_ref * type_repetition_in_bounds * copy_iterator * collection_is_never_read * same_functions_in_if_condition * unnecessary_struct_initialization * clippy on windows * ssl windows
1 parent 432df16 commit 9f2c4e1

21 files changed

Lines changed: 112 additions & 85 deletions

File tree

‎Cargo.toml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ std_instead_of_core = "warn"
363363
tests_outside_test_module = "warn"
364364

365365
# nursery lints to enforce gradually
366+
collection_is_never_read = "warn"
366367
debug_assert_with_mut_call = "warn"
367368
derive_partial_eq_without_eq = "warn"
368369
imprecise_flops = "warn"
@@ -376,6 +377,8 @@ search_is_some = "warn"
376377
significant_drop_in_scrutinee = "warn"
377378
single_option_map = "warn"
378379
trait_duplication_in_bounds = "warn"
380+
type_repetition_in_bounds = "warn"
381+
unnecessary_struct_initialization = "warn"
379382
unused_peekable = "warn"
380383
unused_rounding = "warn"
381384
use_self = "warn"
@@ -387,8 +390,10 @@ checked_conversions = "warn"
387390
cloned_instead_of_copied = "warn"
388391
collapsible_else_if = "warn"
389392
comparison_chain = "warn"
393+
copy_iterator = "warn"
390394
doc_link_with_quotes = "warn"
391395
duration_suboptimal_units = "warn"
396+
elidable_lifetime_names = "warn"
392397
enum_glob_use = "warn"
393398
explicit_deref_methods = "warn"
394399
explicit_into_iter_loop = "warn"
@@ -404,6 +409,7 @@ ip_constant = "warn"
404409
iter_filter_is_ok = "warn"
405410
iter_filter_is_some = "warn"
406411
large_futures = "warn"
412+
large_types_passed_by_value = "warn"
407413
manual_instant_elapsed = "warn"
408414
manual_is_variant_and = "warn"
409415
map_unwrap_or = "warn"
@@ -421,7 +427,9 @@ range_plus_one = "warn"
421427
redundant_else = "warn"
422428
ref_option = "warn"
423429
return_self_not_must_use = "warn"
430+
same_functions_in_if_condition = "warn"
424431
single_char_pattern = "warn"
432+
trivially_copy_pass_by_ref = "warn"
425433
unchecked_time_subtraction = "warn"
426434
uninlined_format_args = "warn"
427435
unnecessary_box_returns = "warn"

‎crates/codegen/src/compile.rs‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,7 @@ impl Compiler {
20912091
self.emit_resume_for_scope(CompilerScope::Module, 1);
20922092
emit!(self, PseudoInstruction::AnnotationsPlaceholder);
20932093

2094-
let (doc, statements) = split_doc_with_range(&body.body, &self.opts);
2094+
let (doc, statements) = split_doc_with_range(&body.body, self.opts);
20952095
let module_start_loc = self.module_start_location(&body.body);
20962096
// Handle annotation bookkeeping before the docstring assignment, as
20972097
// codegen_body() does after _PyCodegen_Module() inserts the prefix set.
@@ -3075,7 +3075,7 @@ impl Compiler {
30753075
}
30763076
ast::Stmt::AugAssign(ast::StmtAugAssign {
30773077
target, op, value, ..
3078-
}) => self.compile_augassign(target, op, value)?,
3078+
}) => self.compile_augassign(target, *op, value)?,
30793079
ast::Stmt::AnnAssign(ast::StmtAnnAssign {
30803080
target,
30813081
annotation,
@@ -4294,7 +4294,7 @@ impl Compiler {
42944294
self.set_qualname();
42954295

42964296
// Handle docstring - store in co_consts[0] if present
4297-
let (doc_info, body) = split_doc_with_range(body, &self.opts);
4297+
let (doc_info, body) = split_doc_with_range(body, self.opts);
42984298
let doc_str = doc_info.as_ref().map(|(doc, _)| doc);
42994299
if let Some(doc) = &doc_str {
43004300
// Docstring present: store in co_consts[0] and set HAS_DOCSTRING flag
@@ -5137,7 +5137,7 @@ impl Compiler {
51375137
self.code_stack.last_mut().unwrap().private = Some(name.to_owned());
51385138

51395139
// 2. Set up class namespace
5140-
let (doc_str, body) = split_doc_with_range(body, &self.opts);
5140+
let (doc_str, body) = split_doc_with_range(body, self.opts);
51415141
let class_body_prefix_range = self.source_line_start_range(firstlineno);
51425142
self.set_source_range(class_body_prefix_range);
51435143

@@ -7004,7 +7004,7 @@ impl Compiler {
70047004
}
70057005

70067006
/// [CPython `compiler_addcompare`](https://github.com/python/cpython/blob/627894459a84be3488a1789919679c997056a03c/Python/compile.c#L2880-L2924)
7007-
fn compile_addcompare(&mut self, op: &ast::CmpOp) {
7007+
fn compile_addcompare(&mut self, op: ast::CmpOp) {
70087008
match op {
70097009
ast::CmpOp::Eq => emit!(
70107010
self,
@@ -7096,7 +7096,7 @@ impl Compiler {
70967096
if mid_comparators.is_empty() {
70977097
self.compile_expression(last_comparator)?;
70987098
self.set_source_range(compare_range);
7099-
self.compile_addcompare(last_op);
7099+
self.compile_addcompare(*last_op);
71007100

71017101
return Ok(());
71027102
}
@@ -7112,7 +7112,7 @@ impl Compiler {
71127112
emit!(self, Instruction::Swap { i: 2 });
71137113
emit!(self, Instruction::Copy { i: 2 });
71147114

7115-
self.compile_addcompare(op);
7115+
self.compile_addcompare(*op);
71167116

71177117
// if comparison result is false, we break with this value; if true, try the next one.
71187118
emit!(self, Instruction::Copy { i: 1 });
@@ -7123,7 +7123,7 @@ impl Compiler {
71237123

71247124
self.compile_expression(last_comparator)?;
71257125
self.set_source_range(compare_range);
7126-
self.compile_addcompare(last_op);
7126+
self.compile_addcompare(*last_op);
71277127

71287128
let end = self.new_block();
71297129
emit!(self, PseudoInstruction::JumpNoInterrupt { delta: end });
@@ -7154,7 +7154,7 @@ impl Compiler {
71547154
self.compile_expression(left)?;
71557155
self.compile_expression(last_comparator)?;
71567156
self.set_source_range(compare_range);
7157-
self.compile_addcompare(last_op);
7157+
self.compile_addcompare(*last_op);
71587158
self.emit_pop_jump_by_condition(condition, target_block);
71597159
return Ok(());
71607160
}
@@ -7167,14 +7167,14 @@ impl Compiler {
71677167
self.set_source_range(compare_range);
71687168
emit!(self, Instruction::Swap { i: 2 });
71697169
emit!(self, Instruction::Copy { i: 2 });
7170-
self.compile_addcompare(op);
7170+
self.compile_addcompare(*op);
71717171
emit!(self, Instruction::ToBool);
71727172
emit!(self, Instruction::PopJumpIfFalse { delta: cleanup });
71737173
}
71747174

71757175
self.compile_expression(last_comparator)?;
71767176
self.set_source_range(compare_range);
7177-
self.compile_addcompare(last_op);
7177+
self.compile_addcompare(*last_op);
71787178
emit!(self, Instruction::ToBool);
71797179
self.emit_pop_jump_by_condition(condition, target_block);
71807180
let end = self.new_block();
@@ -7446,7 +7446,7 @@ impl Compiler {
74467446
fn compile_augassign(
74477447
&mut self,
74487448
target: &ast::Expr,
7449-
op: &ast::Operator,
7449+
op: ast::Operator,
74507450
value: &ast::Expr,
74517451
) -> CompileResult<()> {
74527452
let stmt_range = self.current_source_range;
@@ -7559,7 +7559,7 @@ impl Compiler {
75597559
Ok(())
75607560
}
75617561

7562-
fn compile_op(&mut self, op: &ast::Operator, inplace: bool) {
7562+
fn compile_op(&mut self, op: ast::Operator, inplace: bool) {
75637563
let bin_op = match op {
75647564
ast::Operator::Add => BinaryOperator::Add,
75657565
ast::Operator::Sub => BinaryOperator::Subtract,
@@ -7687,7 +7687,7 @@ impl Compiler {
76877687

76887688
/// Compile a boolean operation as an expression.
76897689
/// This means, that the last value remains on the stack.
7690-
fn compile_bool_op(&mut self, op: &ast::BoolOp, values: &[ast::Expr]) -> CompileResult<()> {
7690+
fn compile_bool_op(&mut self, op: ast::BoolOp, values: &[ast::Expr]) -> CompileResult<()> {
76917691
let boolop_range = self.current_source_range;
76927692
let after_block = self.new_block();
76937693
let (last_value, prefix_values) = values.split_last().unwrap();
@@ -7707,7 +7707,7 @@ impl Compiler {
77077707

77087708
/// Emit CPython-style pseudo conditional jump for short-circuit evaluation.
77097709
/// flowgraph.c lowers it to `COPY 1; TO_BOOL; POP_JUMP_IF_*`.
7710-
fn emit_short_circuit_test(&mut self, op: &ast::BoolOp, target: BlockIdx) {
7710+
fn emit_short_circuit_test(&mut self, op: ast::BoolOp, target: BlockIdx) {
77117711
match op {
77127712
ast::BoolOp::And => {
77137713
emit!(self, PseudoInstruction::JumpIfFalse { delta: target });
@@ -7962,7 +7962,7 @@ impl Compiler {
79627962
func, arguments, ..
79637963
}) => self.compile_call(func, arguments)?,
79647964
ast::Expr::BoolOp(ast::ExprBoolOp { op, values, .. }) => {
7965-
self.compile_bool_op(op, values)?
7965+
self.compile_bool_op(*op, values)?
79667966
}
79677967
ast::Expr::BinOp(ast::ExprBinOp {
79687968
left, op, right, ..
@@ -7972,7 +7972,7 @@ impl Compiler {
79727972

79737973
// Restore full expression range before emitting the operation
79747974
self.set_source_range(range);
7975-
self.compile_op(op, false);
7975+
self.compile_op(*op, false);
79767976
}
79777977
ast::Expr::Subscript(ast::ExprSubscript {
79787978
value, slice, ctx, ..
@@ -12000,10 +12000,10 @@ fn expandtabs(input: &str, tab_size: usize) -> String {
1200012000
expanded_str
1200112001
}
1200212002

12003-
fn split_doc_with_range<'a>(
12004-
body: &'a [ast::Stmt],
12005-
opts: &CompileOpts,
12006-
) -> (Option<(String, TextRange)>, &'a [ast::Stmt]) {
12003+
fn split_doc_with_range(
12004+
body: &[ast::Stmt],
12005+
opts: CompileOpts,
12006+
) -> (Option<(String, TextRange)>, &[ast::Stmt]) {
1200712007
if let Some((ast::Stmt::Expr(expr), body_rest)) = body.split_first() {
1200812008
let doc_comment = match &*expr.value {
1200912009
ast::Expr::StringLiteral(value) => Some((&value.value, expr.value.range())),
@@ -12023,7 +12023,7 @@ fn split_doc_with_range<'a>(
1202312023
}
1202412024

1202512025
#[cfg(test)]
12026-
fn split_doc<'a>(body: &'a [ast::Stmt], opts: &CompileOpts) -> (Option<String>, &'a [ast::Stmt]) {
12026+
fn split_doc(body: &[ast::Stmt], opts: CompileOpts) -> (Option<String>, &[ast::Stmt]) {
1202712027
let (doc, body) = split_doc_with_range(body, opts);
1202812028
(doc.map(|(doc, _)| doc), body)
1202912029
}
@@ -12452,7 +12452,7 @@ def f(x, y, z):
1245212452
in_async_scope: is_async,
1245312453
};
1245412454
compiler.set_qualname();
12455-
let (_doc_str, body) = split_doc(body, &compiler.opts);
12455+
let (_doc_str, body) = split_doc(body, compiler.opts);
1245612456
let start_label = compiler.use_cpython_function_start_label();
1245712457
let is_gen = is_async || compiler.current_symbol_table().is_generator;
1245812458
let stop_iteration_block = if is_gen {

‎crates/codegen/src/ir.rs‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,9 +3291,9 @@ fn optimize_lists_and_sets(
32913291
const VISITED: i32 = -1;
32923292

32933293
/// flowgraph.c SWAPPABLE
3294-
fn is_swappable(instr: &AnyInstruction) -> bool {
3294+
fn is_swappable(instr: AnyInstruction) -> bool {
32953295
matches!(
3296-
(*instr).into(),
3296+
instr.into(),
32973297
AnyOpcode::Real(Opcode::StoreFast | Opcode::PopTop)
32983298
| AnyOpcode::Pseudo(PseudoOpcode::StoreFastMaybeNull)
32993299
)
@@ -3315,17 +3315,22 @@ fn next_swappable_instruction(block: &Block, mut i: usize, lineno: i32) -> Optio
33153315
if i >= block.instruction_used {
33163316
return None;
33173317
}
3318+
33183319
let info = &block.instructions[i];
33193320
let info_lineno = instruction_lineno(info);
3321+
33203322
if lineno >= 0 && info_lineno != lineno {
33213323
return None;
33223324
}
3325+
33233326
if matches!(info.instr, AnyInstruction::Real(Instruction::Nop)) {
33243327
continue;
33253328
}
3326-
if is_swappable(&info.instr) {
3329+
3330+
if is_swappable(info.instr) {
33273331
return Some(i);
33283332
}
3333+
33293334
return None;
33303335
}
33313336
}
@@ -5440,7 +5445,7 @@ fn basicblock_add_jump(
54405445
}
54415446

54425447
/// pycore_opcode_utils.h IS_CONDITIONAL_JUMP_OPCODE
5443-
fn is_conditional_jump_opcode(instr: &AnyInstruction) -> bool {
5448+
fn is_conditional_jump_opcode(instr: AnyInstruction) -> bool {
54445449
matches!(
54455450
instr.real().map(Into::into),
54465451
Some(
@@ -5524,7 +5529,7 @@ fn normalize_jumps_in_block(
55245529
let Some(last_ins) = basicblock_last_instr(&blocks[idx]).copied() else {
55255530
return Ok(());
55265531
};
5527-
if !is_conditional_jump_opcode(&last_ins.instr) {
5532+
if !is_conditional_jump_opcode(last_ins.instr) {
55285533
return Ok(());
55295534
}
55305535
debug_assert!(!last_ins.instr.is_assembler());

‎crates/common/src/format.rs‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,21 @@ impl FormatParse for FormatGrouping {
141141
}
142142
}
143143

144-
impl From<&FormatGrouping> for char {
145-
fn from(fg: &FormatGrouping) -> Self {
144+
impl From<FormatGrouping> for char {
145+
fn from(fg: FormatGrouping) -> Self {
146146
match fg {
147147
FormatGrouping::Comma => ',',
148148
FormatGrouping::Underscore => '_',
149149
}
150150
}
151151
}
152152

153+
impl From<&FormatGrouping> for char {
154+
fn from(fg: &FormatGrouping) -> Self {
155+
Self::from(*fg)
156+
}
157+
}
158+
153159
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
154160
pub enum FormatType {
155161
String,
@@ -322,7 +328,7 @@ impl FormatSpec {
322328
return Err(FormatSpecError::DecimalDigitsTooMany);
323329
}
324330
let (grouping_option, text) = FormatGrouping::parse(text);
325-
if let Some(grouping) = &grouping_option {
331+
if let Some(grouping) = grouping_option {
326332
Self::validate_separator(grouping, text)?;
327333
}
328334
let (precision, text) = parse_precision(text)?;
@@ -349,11 +355,12 @@ impl FormatSpec {
349355
})
350356
}
351357

352-
fn validate_separator(grouping: &FormatGrouping, text: &Wtf8) -> Result<(), FormatSpecError> {
358+
fn validate_separator(grouping: FormatGrouping, text: &Wtf8) -> Result<(), FormatSpecError> {
353359
let mut chars = text.code_points().peekable();
360+
let grouping_char = char::from(grouping);
354361
match chars.peek().and_then(|cp| CodePoint::to_char(*cp)) {
355362
Some(c) if c == ',' || c == '_' => {
356-
if c == char::from(grouping) {
363+
if c == grouping_char {
357364
Err(FormatSpecError::UnspecifiedFormat(c, c))
358365
} else {
359366
Err(FormatSpecError::ExclusiveFormat(',', '_'))

‎crates/host_env/src/crt_fd.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ mod win {
112112
}
113113

114114
#[inline]
115-
pub(super) fn as_raw_fd(&self) -> Raw {
115+
pub(super) fn as_raw_fd(self) -> Raw {
116116
self.fd
117117
}
118118
}
@@ -140,12 +140,13 @@ pub struct Borrowed<'fd> {
140140
inner: BorrowedInner<'fd>,
141141
}
142142

143-
impl<'fd> PartialEq for Borrowed<'fd> {
143+
impl PartialEq for Borrowed<'_> {
144144
fn eq(&self, other: &Self) -> bool {
145145
self.as_raw() == other.as_raw()
146146
}
147147
}
148-
impl<'fd> Eq for Borrowed<'fd> {}
148+
149+
impl Eq for Borrowed<'_> {}
149150

150151
impl fmt::Debug for Borrowed<'_> {
151152
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -250,7 +251,7 @@ impl IntoRawFd for Owned {
250251
}
251252
}
252253

253-
impl<'fd> Borrowed<'fd> {
254+
impl Borrowed<'_> {
254255
/// Create a `crt_fd::Borrowed` from a raw file descriptor.
255256
///
256257
/// # Safety

‎crates/host_env/src/fileutils.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ pub mod windows {
165165
(time_out, nsec_out as _)
166166
}
167167

168-
fn file_time_to_time_t_nsec(in_ptr: &FILETIME) -> (libc::time_t, libc::c_int) {
169-
let in_val: i64 = unsafe { core::mem::transmute_copy(in_ptr) };
168+
fn file_time_to_time_t_nsec(in_ptr: FILETIME) -> (libc::time_t, libc::c_int) {
169+
let in_val: i64 = unsafe { core::mem::transmute_copy(&in_ptr) };
170170
let nsec_out = (in_val % 10_000_000) * 100; // FILETIME is in units of 100 nsec.
171171
let time_out = (in_val / 10_000_000) - SECS_BETWEEN_EPOCHS;
172172
(time_out, nsec_out as _)
@@ -196,10 +196,10 @@ pub mod windows {
196196
)
197197
} else {
198198
(
199-
file_time_to_time_t_nsec(&info.ftCreationTime),
199+
file_time_to_time_t_nsec(info.ftCreationTime),
200200
(0, 0),
201-
file_time_to_time_t_nsec(&info.ftLastWriteTime),
202-
file_time_to_time_t_nsec(&info.ftLastAccessTime),
201+
file_time_to_time_t_nsec(info.ftLastWriteTime),
202+
file_time_to_time_t_nsec(info.ftLastAccessTime),
203203
)
204204
};
205205
let st_nlink = info.nNumberOfLinks as i32;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL