Skip to content

Commit 9d77b25

Browse files
authored
Add more pedantic clippy rules (RustPython#7830)
1 parent d09179a commit 9d77b25

25 files changed

Lines changed: 50 additions & 43 deletions

File tree

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,13 @@ unnested_or_patterns = "warn"
343343

344344
# pedantic lints to enforce gradually
345345
cloned_instead_of_copied = "warn"
346+
collapsible_else_if = "warn"
347+
comparison_chain = "warn"
348+
explicit_into_iter_loop = "warn"
349+
explicit_iter_loop = "warn"
350+
filter_map_next = "warn"
351+
flat_map_option = "warn"
352+
inconsistent_struct_constructor = "warn"
346353
manual_is_variant_and = "warn"
347354
map_unwrap_or = "warn"
348355
must_use_candidate = "warn"

crates/codegen/src/compile.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ impl Compiler {
823823
}
824824
}
825825

826-
for elt in elts.iter() {
826+
for elt in elts {
827827
if let ast::Expr::Starred(ast::ExprStarred { value, .. }) = elt {
828828
// When we hit first star, build sequence with elements so far
829829
if !sequence_built {
@@ -11509,7 +11509,7 @@ impl Compiler {
1150911509
let mut current_string = Wtf8Buf::new();
1151011510
let mut interp_count: u32 = 0;
1151111511

11512-
for tstring in tstring_value.iter() {
11512+
for tstring in tstring_value {
1151311513
self.collect_tstring_strings(
1151411514
tstring,
1151511515
&mut all_strings,
@@ -11534,7 +11534,7 @@ impl Compiler {
1153411534
}
1153511535
);
1153611536

11537-
for tstring in tstring_value.iter() {
11537+
for tstring in tstring_value {
1153811538
self.compile_tstring_interpolations(tstring)?;
1153911539
}
1154011540

crates/codegen/src/ir.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl CodeInfo {
529529

530530
// Final DCE: truncate instructions after terminal ops in linearized blocks.
531531
// This catches dead code created by normalize_jumps after the initial DCE.
532-
for block in blocks.iter_mut() {
532+
for block in &mut blocks {
533533
if let Some(pos) = block
534534
.instructions
535535
.iter()
@@ -540,7 +540,7 @@ impl CodeInfo {
540540
}
541541

542542
// Pre-compute cache_entries for real (non-pseudo) instructions
543-
for block in blocks.iter_mut() {
543+
for block in &mut blocks {
544544
for instr in &mut block.instructions {
545545
if let AnyInstruction::Real(op) = instr.instr {
546546
instr.cache_entries = op.cache_entries() as u32;
@@ -9430,7 +9430,7 @@ impl CodeInfo {
94309430

94319431
// Fix up handler stack_depth in ExceptHandlerInfo using start_depths
94329432
// computed above: depth = start_depth - 1 - preserve_lasti
9433-
for block in self.blocks.iter_mut() {
9433+
for block in &mut self.blocks {
94349434
for ins in &mut block.instructions {
94359435
if let Some(ref mut handler) = ins.except_handler {
94369436
let h_start = start_depths[handler.handler_block.idx()];

crates/compiler-core/src/bytecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ impl CodeUnits {
652652
/// Disable adaptive specialization by setting all counters to unreachable.
653653
/// Used for CPython-compiled bytecode where specialization may not be safe.
654654
pub fn disable_specialization(&self) {
655-
for counter in self.adaptive_counters.iter() {
655+
for counter in &self.adaptive_counters {
656656
counter.store(UNREACHABLE_BACKOFF, Ordering::Relaxed);
657657
}
658658
}

crates/compiler-core/src/marshal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,13 +928,13 @@ pub fn serialize_code<W: Write, C: Constant>(buf: &mut W, code: &CodeObject<C>)
928928
let total_lp_count = code.varnames.len() + cell_only_names.len() + code.freevars.len();
929929
buf.write_u8(Type::Tuple as u8);
930930
write_len(buf, total_lp_count);
931-
for n in code.varnames.iter() {
931+
for n in &code.varnames {
932932
write_marshal_str(buf, n.as_ref());
933933
}
934934
for &n in &cell_only_names {
935935
write_marshal_str(buf, n);
936936
}
937-
for n in code.freevars.iter() {
937+
for n in &code.freevars {
938938
write_marshal_str(buf, n.as_ref());
939939
}
940940
// 10: co_localspluskinds — use the stored kinds directly

crates/stdlib/src/faulthandler.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ mod decl {
609609
// Disable SIGSEGV handler for access violations to avoid double output
610610
if code == 0xC0000005 {
611611
unsafe {
612-
for handler in FAULTHANDLER_HANDLERS.iter_mut() {
612+
for handler in &mut FAULTHANDLER_HANDLERS {
613613
if handler.signum == libc::SIGSEGV {
614614
faulthandler_disable_fatal_handler(handler);
615615
break;
@@ -632,7 +632,7 @@ mod decl {
632632
}
633633

634634
unsafe {
635-
for handler in FAULTHANDLER_HANDLERS.iter_mut() {
635+
for handler in &mut FAULTHANDLER_HANDLERS {
636636
if handler.enabled {
637637
continue;
638638
}
@@ -661,7 +661,7 @@ mod decl {
661661
}
662662

663663
unsafe {
664-
for handler in FAULTHANDLER_HANDLERS.iter_mut() {
664+
for handler in &mut FAULTHANDLER_HANDLERS {
665665
if handler.enabled {
666666
continue;
667667
}
@@ -700,7 +700,7 @@ mod decl {
700700
}
701701

702702
unsafe {
703-
for handler in FAULTHANDLER_HANDLERS.iter_mut() {
703+
for handler in &mut FAULTHANDLER_HANDLERS {
704704
faulthandler_disable_fatal_handler(handler);
705705
}
706706
}

crates/stdlib/src/ssl/cert.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ pub(super) fn cert_der_to_dict_helper(
473473
if let Some(ext) = ext_map.get(&OID_X509_EXT_CRL_DISTRIBUTION_POINTS)
474474
&& let ParsedExtension::CRLDistributionPoints(cdp) = &ext.parsed_extension()
475475
{
476-
for dp in cdp.points.iter() {
476+
for dp in &cdp.points {
477477
if let Some(dist_point) = &dp.distribution_point {
478478
use x509_parser::extensions::DistributionPointName;
479479
if let DistributionPointName::FullName(names) = dist_point {
@@ -583,7 +583,7 @@ pub(super) fn build_verified_chain(
583583
let issuer_name = last_cert.issuer();
584584
let mut found_issuer = false;
585585

586-
for ca_der in ca_certs_der.iter() {
586+
for ca_der in ca_certs_der {
587587
let (_, ca_cert) = match X509Certificate::from_der(ca_der) {
588588
Ok(parsed) => parsed,
589589
Err(_) => continue,

crates/vm/src/builtins/namespace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl Initializer for PyNamespace {
9999
};
100100

101101
// Validate keys are strings and set attributes
102-
for (key, value) in dict.into_iter() {
102+
for (key, value) in dict {
103103
let key_str = key
104104
.downcast_ref::<crate::builtins::PyStr>()
105105
.ok_or_else(|| {

crates/vm/src/builtins/template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Constructor for PyTemplate {
5555
let mut interpolations: Vec<PyObjectRef> = Vec::new();
5656
let mut last_was_str = false;
5757

58-
for item in args.args.iter() {
58+
for item in &args.args {
5959
if let Ok(s) = item.clone().downcast::<PyStr>() {
6060
if last_was_str {
6161
// Concatenate adjacent strings

crates/vm/src/builtins/type.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ impl PyType {
824824
pub(crate) fn init_slots(&self, ctx: &Context) {
825825
// Inherit slots from MRO (mro[0] is self, so skip it)
826826
let mro: Vec<_> = self.mro.read()[1..].to_vec();
827-
for base in mro.iter() {
827+
for base in &mro {
828828
self.inherit_slots(base);
829829
}
830830

@@ -833,7 +833,7 @@ impl PyType {
833833
let mut slot_name_set = std::collections::HashSet::new();
834834

835835
// mro[0] is self, so skip it; self.attributes is checked separately below
836-
for cls in self.mro.read()[1..].iter() {
836+
for cls in &self.mro.read()[1..] {
837837
for &name in cls.attributes.read().keys() {
838838
if name.as_bytes().starts_with(b"__") && name.as_bytes().ends_with(b"__") {
839839
slot_name_set.insert(name);

0 commit comments

Comments
 (0)