Apply some clippy lints by ShaharNaveh · Pull Request #6045 · RustPython/RustPython
examples/call_between_rust_and_python.rs (1)
90-93: Idiomatic Self usage looks good
Switching to Ok(Self { name }) is concise and fully equivalent to the previous explicit type. No functional change introduced.
compiler/core/src/frozen.rs (2)
60-60: Pure formatting – no issues
88-88: Pure formatting – no issues
stdlib/src/unicodedata.rs (1)
19-28: Iteration simplification approved
Dropping the explicit .into_iter() makes the loop cleaner without changing semantics.
vm/src/builtins/super.rs (1)
173-178: Minor style improvement acknowledged
Iterating with for cls in &mro is the preferred idiom. Behaviour remains unchanged.
vm/src/stdlib/itertools.rs (1)
1383-1386: Iteration now uses &zelf.pools – idiomatic and fine
Switching from self.pools.iter() to for element in &zelf.pools is equivalent, more concise, and keeps the borrow checker happy. No functional or performance concerns here.
vm/src/builtins/dict.rs (1)
279-285: Loop over kwargs is correct and more idiomatic
Dropping the explicit .into_iter() simplifies the code without changing semantics—the for (key, value) in kwargs pattern consumes the KwArgs value exactly as before. Insertions into self.entries remain unchanged.
vm/src/builtins/slice.rs (1)
231-231: LGTM! Idiomatic iteration syntax improvement.
This change from iterating over an array to iterating over a slice reference follows Rust best practices and maintains identical semantics while using more concise syntax.
vm/src/builtins/str.rs (1)
1524-1524: LGTM! Improved type consistency using Self.
Replacing the explicit type PyRef<PyStr> with Self improves code maintainability and follows Rust conventions for self-referential types. The transmute logic and safety invariants remain unchanged.
wtf8/src/core_str_count.rs (2)
98-98: LGTM! Enabling compile-time evaluation.
Converting to const fn allows this function to be evaluated at compile time when arguments are known, providing a performance benefit without changing runtime behavior.
106-106: LGTM! Enabling compile-time evaluation.
Converting to const fn allows this function to be evaluated at compile time when arguments are known, providing a performance benefit without changing runtime behavior.
src/shell/helper.rs (1)
57-57: LGTM! Enabling compile-time construction.
Converting the constructor to const fn allows ShellHelper instances to be created at compile time when parameters are constant, following the PR's pattern of increasing const-correctness throughout the codebase.
vm/src/stdlib/posix.rs (7)
519-519: LGTM: Idiomatic iteration simplification.
Removing the explicit .into_iter() call is more idiomatic since vectors automatically implement IntoIterator for direct iteration.
1606-1608: LGTM: Appropriate const fn for libc macro.
The WIFSIGNALED libc macro performs bit manipulation operations that are const-evaluable, making this const fn annotation appropriate.
1611-1613: LGTM: Appropriate const fn for libc macro.
The WIFSTOPPED libc macro is const-evaluable, making this const fn annotation appropriate.
1616-1618: LGTM: Appropriate const fn for libc macro.
The WIFEXITED libc macro is const-evaluable, making this const fn annotation appropriate.
1621-1623: LGTM: Appropriate const fn for libc macro.
The WTERMSIG libc macro is const-evaluable, making this const fn annotation appropriate.
1626-1628: LGTM: Appropriate const fn for libc macro.
The WSTOPSIG libc macro is const-evaluable, making this const fn annotation appropriate.
1631-1633: LGTM: Appropriate const fn for libc macro.
The WEXITSTATUS libc macro is const-evaluable, making this const fn annotation appropriate.
compiler/core/src/marshal.rs (6)
117-143: LGTM: Well-designed convenience methods.
These convenience methods provide type-safe ways to read fixed-size data types with proper error handling and const generic array sizes. The consistent use of little-endian byte order aligns with the marshaling format requirements.
149-151: LGTM: Consistent borrowed string reading method.
The read_str_borrow method follows the established pattern of the ReadBorrowed trait and includes proper UTF-8 validation with appropriate error handling.
277-277: LGTM: Improved type relationships through associated types.
Adding the ConstantBag associated type and updating the constant_bag method signature improves type safety and makes the relationship between MarshalBag and ConstantBag explicit in the type system.
Also applies to: 315-315
320-320: LGTM: Proper implementation of associated type constraint.
The implementation correctly handles the new ConstantBag associated type by setting it to Self and returning self in the constant_bag method, which is appropriate for the default case.
Also applies to: 388-390
465-465: LGTM: Enhanced type constraints in Dumpable trait.
Adding the Constant: Constant associated type constraint improves type safety and makes the relationship between Dumpable and Constant types explicit.
518-532: LGTM: Consistent write convenience methods.
These convenience methods mirror the Read trait additions and provide type-safe ways to write fixed-size data types with consistent little-endian byte order. The implementation follows established patterns and improves API usability.
wtf8/src/lib.rs (6)
94-96: LGTM! Idiomatic use of Self in constructor.
Using Self instead of the explicit type name improves code clarity and maintainability.
102-107: LGTM! Consistent use of Self in return type.
The change from Option<CodePoint> to Option<Self> maintains consistency with the constructor pattern improvements throughout the codebase.
113-117: LGTM! Constructor consistency improved.
Using Self { value } instead of CodePoint { value } follows Rust best practices for constructor implementations.
246-248: LGTM! Trait implementation improvement.
Using &Self::Target instead of the explicit type is more idiomatic and flexible.
639-643: LGTM! Clean trait implementation.
The AsRef<Self> implementation using Self is idiomatic and improves code consistency.
949-952: LGTM! Improved constructor method.
Using Box::default() instead of Default::default() and returning Box<Self> makes the code more concise and idiomatic.
vm/src/stdlib/typing.rs (1)
168-168: LGTM! Idiomatic constructor call.
Using Self::new instead of TypeAliasType::new is more idiomatic within the impl block and improves code consistency.
vm/src/stdlib/thread.rs (1)
289-291: LGTM! Performance improvement with const fn.
Converting allocate_lock to a const fn enables compile-time evaluation while maintaining the same functionality. This aligns with the broader pattern in the PR of making eligible functions const.
compiler/codegen/src/unparse.rs (1)
467-470: LGTM! Simplified iteration syntax.
Replacing .iter() with direct iteration over &args.kwonlyargs is more idiomatic and concise while maintaining the same functionality.
vm/src/stdlib/ast/python.rs (1)
74-74: LGTM! Idiomatic method call.
Using Self::__init__ instead of NodeAst::__init__ is more idiomatic within the impl block and improves code consistency with the broader codebase changes.
vm/src/stdlib/io.rs (1)
3603-3606: const fn conversion is sound
The getter is pure and independent of runtime state, so making it const fn is perfectly safe and aligns with the broader const-ification effort.
vm/src/builtins/namespace.rs (1)
64-64: LGTM: Idiomatic iteration simplification.
Removing the explicit .into_iter() call is correct and more idiomatic when the collection already implements IntoIterator.
vm/src/stdlib/symtable.rs (1)
72-77: LGTM: Appropriate const fn conversion.
Converting this method to const fn is correct since it only performs pattern matching on enum variants, which can be evaluated at compile time.
common/src/boxvec.rs (1)
168-168: LGTM: More idiomatic range syntax.
Using index..=index instead of index..index + 1 is more readable and idiomatic for representing a single-element range, while maintaining identical functionality.
compiler/literal/src/float.rs (1)
47-52: LGTM: Appropriate const fn conversion.
Converting this function to const fn is correct since it only performs pattern matching on primitive types and returns string literals, enabling beneficial compile-time evaluation.
vm/src/builtins/traceback.rs (2)
72-72: LGTM: Idiomatic use of Self keyword.
Replacing explicit type references with Self is more idiomatic and maintainable Rust code.
78-78: LGTM: Consistent Self keyword usage.
Using Self::new instead of explicit type name maintains consistency and follows Rust best practices.
vm/src/builtins/genericalias.rs (4)
341-341: LGTM: Idiomatic iteration simplification.
The direct iteration over the tuple reference is more idiomatic than explicitly calling .iter().
390-390: LGTM: Consistent iteration style improvement.
Direct iteration over the tuple reference maintains consistency with the idiomatic Rust style being applied throughout the codebase.
487-487: LGTM: Maintains consistency in iteration style.
This change aligns with the pattern of simplifying iteration syntax throughout the file.
575-575: LGTM: Idiomatic array iteration.
Direct iteration over the array reference is more concise and idiomatic than explicitly calling .iter().
common/src/format.rs (2)
392-392: LGTM: More idiomatic inclusive range syntax.
Using 1..=sep_cnt is clearer and more idiomatic than 1..sep_cnt + 1 when including the end value.
757-757: LGTM: Idiomatic use of Self.
Using Self:: instead of the explicit type name is more idiomatic and maintainable within impl blocks.
vm/src/builtins/code.rs (4)
110-110: LGTM: Minor formatting improvement.
The additional blank line improves code readability.
127-145: LGTM: Simplified match arms improve readability.
Removing the redundant bytecode:: prefix makes the match arms cleaner and more readable. The consistency across all arms is good.
147-147: LGTM: Formatting improvement.
175-175: LGTM: Idiomatic use of Self in trait implementation.
Using Self as the return type is more idiomatic and maintainable than the explicit type name in trait implementations.
vm/src/builtins/tuple.rs (6)
234-234: LGTM: Idiomatic use of Self in return type.
Using PyRef<Self> is more concise and maintainable than the explicit generic type in the return position.
240-240: LGTM: Consistent use of Self in transmute.
Using Self in the transmute maintains consistency with the return type and improves maintainability.
341-341: LGTM: Idiomatic iteration over slice reference.
Direct iteration over &self.elements is more concise than explicitly calling .iter().
485-485: LGTM: Consistent Self usage in transmute.
Using Self in the transmute operation maintains consistency with the broader pattern of idiomatic type references.
492-492: LGTM: Maintains consistency in transmute operations.
499-499: LGTM: Completes consistent Self usage pattern.
This final transmute change maintains consistency with the idiomatic use of Self throughout the implementation.
vm/src/frame.rs (1)
344-353: const fn likely fails to compile on stable Rust
Cell::<u32>::get() is not yet a const fn on stable.
Marking ExecutingFrame::lasti as const fn will therefore break the build (unless you compile with nightly and the relevant feature flags).
Consider reverting to a plain #[inline(always)] fn, or gate the const with a feature flag.
-#[inline(always)] -const fn lasti(&self) -> u32 { +#[inline(always)] +fn lasti(&self) -> u32 {
Please run cargo check --all-targets to verify compilation.
compiler/codegen/src/compile.rs (3)
363-379: Initialization looks good – no actionable issues spotted
The refactor to use Self { .. } keeps the constructor readable and aligns with idiomatic struct-literal style. No functional impact.
383-385: is_two_element_slice promoted to const fn
Good call; this allows the pattern-check to be evaluated in a const‐context if ever needed and is zero-cost at runtime.
No concerns.
4551-4567: Reliable fallback to empty Parameters
Introducing a cached default_params avoids repeated Parameters::default() construction – nice micro-optimisation.
No further comments.
compiler/literal/src/escape.rs (9)
11-16: LGTM! Proper const fn conversion and Self usage.
The conversion to const fn is appropriate here since this is a simple pattern match with no side effects. Using Self:: variants instead of Quote:: improves code consistency and maintainability.
21-31: LGTM! Consistent Self usage in pattern matches.
The updated pattern matches using Self::Single and Self::Double maintain consistency with the swap method changes and follow Rust idioms.
98-101: LGTM! Appropriate const fn conversion.
The with_forced_quote constructor can be safely marked as const fn since it only performs struct initialization without any runtime computation.
112-114: LGTM! Valid const fn conversion for accessor method.
The str_repr method is a simple wrapper that returns a struct, making it suitable for const fn.
172-181: LGTM! Appropriate const fn for nested helper.
The nested stop function is correctly marked as const fn since it only constructs and returns an EscapeLayout struct without side effects.
286-293: LGTM! Proper const fn conversions for constructors.
All three AsciiEscape constructor methods (new, with_forced_quote, and bytes_repr) are appropriately converted to const fn as they only perform struct initialization.
Also applies to: 290-293, 304-306
332-332: LGTM! Simplified iteration syntax.
Removing the explicit .iter() calls and iterating directly over slices is more idiomatic Rust and slightly more efficient.
Also applies to: 416-416
346-355: LGTM! Consistent const fn pattern for nested helper.
The nested stop function in AsciiEscape follows the same pattern as in UnicodeEscape, properly marked as const fn.
373-379: LGTM! Appropriate const fn for utility function.
The escaped_char_len function performs only compile-time deterministic pattern matching, making it suitable for const fn.
vm/sre_engine/src/engine.rs (9)
71-73: LGTM! Simple getter method appropriately marked const.
The last_index method is a straightforward field accessor that can be safely evaluated at compile time.
1057-1059: LGTM! Arithmetic computation suitable for const fn.
The remaining_codes method performs simple arithmetic on compile-time accessible fields, making it appropriate for const fn.
1061-1063: LGTM! Simple arithmetic operation for const fn.
The remaining_chars method calculates the difference between two usize values, which is a const-safe operation.
1100-1102: LGTM! State mutation method correctly marked const.
While this method mutates self.code_position, the const keyword here refers to the ability to call this method in const contexts when the receiver is mutable, which is correct.
1108-1111: LGTM! Simple comparison suitable for const fn.
The at_beginning method performs a simple field comparison that can be evaluated at compile time.
1113-1115: LGTM! Field comparison appropriate for const fn.
The at_end method compares cursor position with request end, which is const-safe.
1147-1158: LGTM! Complex logic correctly implemented as const fn.
The can_success method contains conditional logic that can all be evaluated at compile time since it only involves field comparisons and boolean operations.
1166-1168: LGTM! Method delegation appropriate for const fn.
The next_offset method delegates to next_at with simple arithmetic, suitable for const evaluation.
1171-1179: LGTM! Struct construction with field update syntax.
The next_at method creates a new instance using struct update syntax, which is const-safe. The field assignments and struct literal are all compile-time operations.
compiler/core/src/bytecode.rs (13)
45-45: LGTM! Formatting improvements enhance readability.
The spacing adjustments around trait implementations and function definitions improve code consistency and readability without affecting functionality.
Also applies to: 48-48, 67-67, 69-69, 71-71, 73-73, 75-75, 81-81, 88-88, 99-99, 103-103, 107-107, 113-113, 119-119
182-184: LGTM! Appropriate const fn conversion.
Converting OpArgByte::null() to const fn is correct as it's a simple constructor with no side effects that can be evaluated at compile time.
199-201: LGTM! Appropriate const fn conversions.
Both OpArg::null() and OpArg::instr_size() are correctly converted to const fn as they perform simple operations without side effects that can be evaluated at compile time.
Also applies to: 205-207
247-249: LGTM! Appropriate const fn conversion.
Converting OpArgState::reset() to const fn is correct as it performs a simple assignment operation that can be evaluated at compile time.
254-254: LGTM! Consistent formatting improvements.
The spacing adjustments in trait implementations enhance code readability and maintain consistency across the codebase.
Also applies to: 264-264, 276-276, 288-288
317-319: LGTM! Appropriate const fn conversion.
Converting Arg<T>::marker() to const fn is correct as it only constructs a PhantomData which is const-evaluable.
325-333: LGTM! Const fn conversions appear valid.
The const fn conversions for Arg<T> methods are appropriate, assuming the underlying trait implementations (Into, OpArgType) support const evaluation. Since this code compiles, these conversions are valid.
Also applies to: 334-337, 339-342, 346-350
358-358: LGTM! Consistent formatting improvements.
The spacing adjustments continue to improve code readability and maintain consistency.
Also applies to: 378-378, 402-402
715-715: LGTM! Appropriate const fn conversion and formatting.
Converting CodeUnit::new() to const fn is correct as it's a simple struct constructor, and the spacing adjustments improve readability.
Also applies to: 718-718, 752-754
769-769: LGTM! Consistent formatting improvements.
The spacing adjustments in trait implementations maintain code consistency.
Also applies to: 775-775
886-886: LGTM! Improved byte literal display formatting.
The change from Debug formatting to using escape_ascii() with raw string literal provides more consistent and readable output for byte constants, aligning better with Python's byte literal representation.
1253-1269: LGTM! Appropriate const fn conversions for pattern matching methods.
Converting Instruction::label_arg() and Instruction::unconditional_branch() to const fn is correct as they perform simple pattern matching operations that can be evaluated at compile time.
Also applies to: 1280-1290
808-808: LGTM! Comprehensive formatting improvements.
All the spacing adjustments throughout the file improve code readability and maintain consistent formatting without affecting functionality.
Also applies to: 834-834, 869-869, 905-905, 908-908, 1018-1018, 1024-1024, 1616-1616, 1618-1618, 1620-1620, 1622-1622, 1624-1624, 1628-1628, 1632-1632, 1636-1636, 1640-1640