Skip to content

Fix nightly clippy warnings #5803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 15, 2025
Merged

Fix nightly clippy warnings #5803

merged 2 commits into from
Jun 15, 2025

Conversation

youknowone
Copy link
Member

@youknowone youknowone commented Jun 15, 2025

Summary by CodeRabbit

  • Style
    • Updated string formatting across various modules to use modern Rust inline variable interpolation, improving readability and consistency of debug and error messages.
  • Refactor
    • Simplified buffer assignment and struct initialization logic in a few places for clearer and more direct code.

Copy link

coderabbitai bot commented Jun 15, 2025

Walkthrough

This update modernizes string formatting throughout the codebase by adopting Rust's inline variable interpolation syntax (Rust 1.58+), replacing older positional formatting and explicit argument passing. Additionally, minor refactoring was performed to simplify assignment and control flow in a few locations, with no changes to logic, error handling, or public interfaces.

Changes

File(s) Change Summary
src/lib.rs, src/shell.rs, vm/src/eval.rs, vm/src/frame.rs Updated debug log statements to use Rust's inline variable formatting syntax and added conditional debug compilation where applicable.
stdlib/src/binascii.rs, stdlib/src/csv.rs, vm/src/builtins/complex.rs, vm/src/builtins/object.rs, vm/src/builtins/property.rs, vm/src/protocol/number.rs, vm/src/stdlib/ctypes/base.rs, vm/src/stdlib/ctypes/structure.rs, vm/src/stdlib/posix.rs, vm/src/stdlib/sys.rs, vm/src/vm/compile.rs, vm/src/exceptions.rs Modernized string formatting in error and warning messages to use inline variable interpolation.
vm/src/buffer.rs Updated debug macros in packing/unpacking to use inline formatting for debug output.
vm/src/builtins/super.rs Simplified assignment logic by replacing mem::swap with direct assignment to the lock guard.
vm/src/codecs.rs Minor control flow simplification: removed explicit return statements for early returns.
vm/src/stdlib/io.rs Replaced buffer swap with direct assignment for buffer replacement after reading.
vm/src/stdlib/ctypes/function.rs Replaced manual null-terminated string construction with CString creation and validation for function names.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Application
    participant Logger

    User->>Application: Trigger action (e.g., command, REPL, error)
    Application->>Logger: Log message with inline variable formatting
    Logger-->>Application: Handles formatted output
    Application-->>User: Continue execution or return result
Loading

Poem

Rusty strings now shine anew,
With curly braces peeking through!
Logs and errors, neat and bright,
Formatting woes are out of sight.
Swaps and returns, now concise—
This codebase hops with modern spice!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 011f194 and 5677cf8.

📒 Files selected for processing (21)
  • src/lib.rs (1 hunks)
  • src/shell.rs (1 hunks)
  • stdlib/src/binascii.rs (1 hunks)
  • stdlib/src/csv.rs (2 hunks)
  • vm/src/buffer.rs (2 hunks)
  • vm/src/builtins/complex.rs (1 hunks)
  • vm/src/builtins/object.rs (1 hunks)
  • vm/src/builtins/property.rs (1 hunks)
  • vm/src/builtins/super.rs (2 hunks)
  • vm/src/codecs.rs (2 hunks)
  • vm/src/eval.rs (1 hunks)
  • vm/src/exceptions.rs (3 hunks)
  • vm/src/frame.rs (1 hunks)
  • vm/src/protocol/number.rs (4 hunks)
  • vm/src/stdlib/ctypes/base.rs (1 hunks)
  • vm/src/stdlib/ctypes/function.rs (2 hunks)
  • vm/src/stdlib/ctypes/structure.rs (1 hunks)
  • vm/src/stdlib/io.rs (1 hunks)
  • vm/src/stdlib/posix.rs (2 hunks)
  • vm/src/stdlib/sys.rs (2 hunks)
  • vm/src/vm/compile.rs (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/shell.rs
  • stdlib/src/csv.rs
🚧 Files skipped from review as they are similar to previous changes (19)
  • vm/src/stdlib/ctypes/structure.rs
  • vm/src/stdlib/ctypes/base.rs
  • vm/src/eval.rs
  • vm/src/vm/compile.rs
  • vm/src/builtins/super.rs
  • vm/src/stdlib/ctypes/function.rs
  • vm/src/buffer.rs
  • vm/src/builtins/object.rs
  • vm/src/builtins/complex.rs
  • stdlib/src/binascii.rs
  • vm/src/builtins/property.rs
  • vm/src/frame.rs
  • src/lib.rs
  • vm/src/codecs.rs
  • vm/src/stdlib/sys.rs
  • vm/src/stdlib/io.rs
  • vm/src/stdlib/posix.rs
  • vm/src/protocol/number.rs
  • vm/src/exceptions.rs
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: Run tests under miri
  • GitHub Check: Run snippets and cpython tests on wasm-wasi
  • GitHub Check: Check the WASM package and demo
  • GitHub Check: Ensure compilation on various targets
  • GitHub Check: Run snippets and cpython tests (ubuntu-latest)
  • GitHub Check: Check Rust code with rustfmt and clippy
  • GitHub Check: Run snippets and cpython tests (windows-latest)
  • GitHub Check: Run snippets and cpython tests (macos-latest)
  • GitHub Check: Run rust tests (windows-latest)
  • GitHub Check: Run rust tests (macos-latest)
  • GitHub Check: Run rust tests (ubuntu-latest)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (9)
src/shell.rs (1)

155-155: Consider whether logging raw REPL input is desirable

debug!("You entered {line:?}"); will emit every line the user types – including potentially sensitive data – to the log at debug level.
If the interactive shell can ever run in production or be embedded in another process that collects logs, this could leak secrets.

-debug!("You entered {line:?}");
+// Debug-level logging can expose user input verbatim; enable only when really useful.
+debug!(target: "repl", "You entered {line:?}");

Alternatively gate the statement behind a feature flag or redact long inputs.

vm/src/frame.rs (1)

1670-1670: Debug message looks good, just watch allocation cost

debug!("Exception raised: {exception:?} …") allocates the full Debug representation of the exception even when the debug level is disabled, because log still formats the message inside the macro.
If the exception objects can be large or contain heavy .repr() implementations, you might prefer:

if log::log_enabled!(log::Level::Debug) {
    debug!("Exception raised: {exception:?} with cause: {cause:?}");
}

Purely optional; current code is acceptable for most cases.

vm/src/stdlib/ctypes/base.rs (1)

254-254: Nit: minor wording tweak

The message now reads “Array length must be >= 0, not {n}”.
Consider adding a space after the comma for consistency with other errors:

-return Err(vm.new_value_error(format!("Array length must be >= 0, not {n}")));
+return Err(vm.new_value_error(format!("array length must be >= 0, not {n}")));

Also lower-case the first word to follow CPython style. Optional.

vm/src/vm/compile.rs (1)

52-52: OK, but think about back-pressure instead of process::exit

Logging improved; however, the block still terminates the whole VM on an IO error.
For library users this is surprising. Returning an Err upward would give callers control.

Out of scope for this PR, just flagging.

vm/src/stdlib/ctypes/function.rs (1)

80-86: Consider using CString to guard against interior NULs

format!("{function}\0") is concise, but it silently accepts function names that might already contain '\0', producing an over-long C string.
Wrapping the name in CString::new() would validate this upfront and avoid undefined behaviour when the symbol is looked up.

+use std::ffi::CString;
 ...
-        let terminated = format!("{function}\0");
-        let pointer: Symbol<'_, FP> = unsafe {
-            library
-                .get(terminated.as_bytes())
+        let terminated = CString::new(function)
+            .map_err(|_| vm.new_value_error("Function name contains NUL byte".to_owned()))?;
+        let pointer: Symbol<'_, FP> = unsafe {
+            library
+                .get(terminated.as_c_str().to_bytes_with_nul())
                 .map_err(|err| err.to_string())
                 .map_err(|err| vm.new_attribute_error(err))?
         };

Would you like a follow-up patch covering the additional use std::ffi::CString; import and the error mapping?

vm/src/builtins/object.rs (1)

55-62: Minor wording polish for the new error message

"class {name} without an implementation for abstract method …" reads a little awkwardly.
Consider adding a verb for clarity:

-return Err(vm.new_type_error(format!(
-    "class {name} without an implementation for abstract method '{methods}'"
-)));
+return Err(vm.new_type_error(format!(
+    "class {name} has no implementation for abstract method '{methods}'"
+)));

Same tweak applies to the plural branch below.

stdlib/src/csv.rs (1)

350-351: Redundant to_string() allocation

format! already returns a String; the extra .to_string() just clones the
buffer.

-return Err(vm.new_type_error(
-    format!("field_size_limit() takes at most 1 argument ({arg_len} given)")
-        .to_string(),
-));
+return Err(vm.new_type_error(format!(
+    "field_size_limit() takes at most 1 argument ({arg_len} given)"
+)));

This shaves an allocation and removes a clippy inherent_to_string warning.

vm/src/exceptions.rs (1)

208-210: Minor allocation nit: avoid an extra String

filename_suffix = format!(" ({filename})"); allocates a new String.
Because filename_suffix is only appended once, a cheaper option is:

-filename_suffix = format!(" ({filename})");
+filename_suffix.push_str(" (");
+filename_suffix.push_str(filename.as_str());
+filename_suffix.push(')');

Not critical, just a micro-optimisation.

vm/src/builtins/complex.rs (1)

65-72: Consider printing the type’s Python-level name

{ret_class} ends up using Display for Py<PyType>, which produces something like <class 'complex'>.
If you want the message to mirror CPython more closely and avoid the pointer-like wrapper you could use:

-format!(
-    "__complex__ returned non-complex (type {ret_class}).  \
+format!(
+    "__complex__ returned non-complex (type {}).  \
     The ability to return an instance of a strict subclass of complex \
     is deprecated, and may be removed in a future version of Python.",
-    ret_class.name(),   // <-- uses the type’s __name__
-)
+    ret_class.name(),
+)

Purely cosmetic; existing code compiles and behaves correctly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4e094ea and 011f194.

📒 Files selected for processing (21)
  • src/lib.rs (1 hunks)
  • src/shell.rs (1 hunks)
  • stdlib/src/binascii.rs (1 hunks)
  • stdlib/src/csv.rs (2 hunks)
  • vm/src/buffer.rs (2 hunks)
  • vm/src/builtins/complex.rs (1 hunks)
  • vm/src/builtins/object.rs (1 hunks)
  • vm/src/builtins/property.rs (1 hunks)
  • vm/src/builtins/super.rs (1 hunks)
  • vm/src/codecs.rs (2 hunks)
  • vm/src/eval.rs (1 hunks)
  • vm/src/exceptions.rs (3 hunks)
  • vm/src/frame.rs (1 hunks)
  • vm/src/protocol/number.rs (4 hunks)
  • vm/src/stdlib/ctypes/base.rs (1 hunks)
  • vm/src/stdlib/ctypes/function.rs (1 hunks)
  • vm/src/stdlib/ctypes/structure.rs (1 hunks)
  • vm/src/stdlib/io.rs (1 hunks)
  • vm/src/stdlib/posix.rs (2 hunks)
  • vm/src/stdlib/sys.rs (2 hunks)
  • vm/src/vm/compile.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: Run tests under miri
  • GitHub Check: Run snippets and cpython tests (ubuntu-latest)
  • GitHub Check: Run snippets and cpython tests on wasm-wasi
  • GitHub Check: Run snippets and cpython tests (macos-latest)
  • GitHub Check: Run rust tests (ubuntu-latest)
  • GitHub Check: Run snippets and cpython tests (windows-latest)
  • GitHub Check: Check Rust code with rustfmt and clippy
  • GitHub Check: Check the WASM package and demo
  • GitHub Check: Run rust tests (windows-latest)
  • GitHub Check: Ensure compilation on various targets
  • GitHub Check: Run rust tests (macos-latest)
🔇 Additional comments (17)
vm/src/eval.rs (1)

6-6: LGTM – modernised formatting only

Inline interpolation compiles fine and is cheaper to read. No further issues spotted.

vm/src/stdlib/ctypes/structure.rs (1)

56-57: Modernised formatting looks good

Inline named-parameter formatting is clearer and resolves the recent clippy::uninlined_format_args lint.
No further issues spotted.

vm/src/builtins/super.rs (1)

128-130: Nice simplification – avoids std::mem::swap

Replacing the swap with direct assignment via the write guard is clearer and equally safe; lock scope remains minimal because the heavy construction happens beforehand.

stdlib/src/binascii.rs (1)

758-760: Updated error string – no concerns

The inline placeholder removes the unnecessary positional argument, matching the clippy fix across the PR.

vm/src/stdlib/posix.rs (2)

1992-1992: Modernize formatting with inline variable interpolation
Replacing format!("{:?}", variant) with format!("{variant:?}") here is correct and consistent with the PR’s style updates.


2188-2188: Modernize formatting with inline variable interpolation
This change mirrors the one above for sysconf_names and correctly uses named interpolation for variant.

vm/src/builtins/property.rs (1)

135-136: Use inline formatting for error message
Switching to "{func_args_len}" interpolation is stylistic only and aligns with the project’s formatting conventions.

vm/src/buffer.rs (2)

367-367: Use inline variable formatting in debug log
Updating to debug!("code: {code:?}") follows the new inline formatting style and has no impact on functionality.


410-410: Use inline variable formatting in debug log
Consistent with other debug statements, this change improves clarity without altering behavior.

vm/src/stdlib/io.rs (1)

1163-1181: Clearer vector restoration via direct assignment – looks good

Replacing the previous buffer-swap logic with a single
*v = read_buf.take(); cleanly moves the data back into the caller-supplied Vec<u8> without extra allocations or indirection.
Behavior, ownership semantics, and safety remain intact. Nice simplification.

vm/src/stdlib/sys.rs (1)

320-323: Modernised formatting looks good

The change to inline interpolation ({e}, {threshold:?}) keeps behaviour intact and silences the new clippy lint.
No functional, performance or style issues spotted here.

Also applies to: 726-727

vm/src/codecs.rs (2)

420-423: Redundant return successfully removed – stylistic win

Replacing return Some(Self::Utf32Be)/return None style with bare expression keeps the arm consistent with the others and is more idiomatic Rust. No functional impact noticed.


1108-1120: Uniform early-exit style in replace_errors

The last branch now ends with Err(bad_err_type(err, vm)) instead of an explicit return. This mirrors the earlier branches, trims one level of indentation, and leaves behaviour unchanged. 👍

vm/src/exceptions.rs (2)

212-218: Inline-interpolation upgrade looks good

Switching to writeln!(output, " {l_text}")?; matches the new Rust 1.58-style formatting adopted in the rest of the PR. Functionality unchanged.


1613-1620: Consistent formatting in PySyntaxError::__str__

Modern interpolation ({msg}, {lineno}) improves readability with no behavioural change. Verified that the underlying variables are already PyStrRef or String, so Display is implemented.

src/lib.rs (2)

200-200: Modernize debug log for command with inline variable interpolation
Clippy warnings are resolved and behavior is unchanged.


205-205: Modernize debug log for module with inline variable interpolation
Consistent with the new Rust 1.58+ formatting style and no change in functionality.

@youknowone
Copy link
Member Author

@coolreader18 redoxer-action is broken

@youknowone youknowone merged commit 2c61a12 into RustPython:main Jun 15, 2025
11 of 23 checks passed
@youknowone youknowone deleted the clippy branch June 15, 2025 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant