Skip to content

Fix future clippy warnings #6103

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 1 commit into from
Aug 20, 2025
Merged

Conversation

youknowone
Copy link
Member

@youknowone youknowone commented Aug 20, 2025

Summary by CodeRabbit

  • Chores

    • Updated minimum Rust toolchain requirement to 1.87.0.
  • Refactor

    • Replaced modulo-based divisibility checks with is_multiple_of across various components for clearer intent and consistency. No functional behavior changes.
  • Style

    • Minor condition style improvements in internal logic to enhance readability without altering outcomes.

Copy link
Contributor

coderabbitai bot commented Aug 20, 2025

Walkthrough

Updates workspace Rust toolchain requirement to 1.87.0. Refactors several divisibility checks from modulo operations to is_multiple_of across array processing, struct unpacking, memory view casting, and UTF-8 counting code paths. No public API changes or behavioral adjustments reported.

Changes

Cohort / File(s) Summary of changes
Toolchain requirement
Cargo.toml
Bumped [workspace.package].rust-version from "1.85.0" to "1.87.0".
Divisibility check idiom update
stdlib/src/array.rs, stdlib/src/pystruct.rs, vm/src/builtins/memory.rs, wtf8/src/core_str_count.rs
Replaced modulo-based divisibility checks with is_multiple_of(...) in array byte handling, struct unpacking buffer alignment, memoryview itemsize validation, and a const assertion in UTF-8 char counting. No control-flow or error message changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I hop through code with tidy feet,
Swapping mods for multiples neat.
Rust now speaks in 1.87’s tune,
Arrays and views all hum in rune.
Wtf8 counts, aligned just right—
A rabbit’s refactor, swift and light. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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
Contributor

@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: 0

🧹 Nitpick comments (1)
vm/src/builtins/memory.rs (1)

746-748: Consider guarding against zero-sized item formats before the divisibility check.

Using is_multiple_of is fine; however, a zero itemsize would now bypass a panic and reach the division that follows (Line 760), which could divide by zero if a zero-sized format were ever parsed. If FormatSpec guarantees size > 0, this is a non-issue—but an explicit guard is cheap and future-proof.

Proposed minimal guard:

 fn cast_to_1d(&self, format: PyStrRef, vm: &VirtualMachine) -> PyResult<Self> {
     let format_spec = Self::parse_format(format.as_str(), vm)?;
     let itemsize = format_spec.size();
+    if itemsize == 0 {
+        return Err(vm.new_type_error("memoryview: itemsize must be non-zero"));
+    }
     if !self.desc.len.is_multiple_of(itemsize) {
         return Err(vm.new_type_error("memoryview: length is not a multiple of itemsize"));
     }

If you prefer to rely on the invariant from FormatSpec, please confirm that size() can never be zero.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 527ce3a and d8e1112.

📒 Files selected for processing (5)
  • Cargo.toml (1 hunks)
  • stdlib/src/array.rs (3 hunks)
  • stdlib/src/pystruct.rs (1 hunks)
  • vm/src/builtins/memory.rs (1 hunks)
  • wtf8/src/core_str_count.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

**/*.rs: Follow the default rustfmt code style (cargo fmt to format)
Always run clippy to lint code (cargo clippy) before completing tasks. Fix any warnings or lints that are introduced by your changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust

Files:

  • vm/src/builtins/memory.rs
  • stdlib/src/pystruct.rs
  • wtf8/src/core_str_count.rs
  • stdlib/src/array.rs
🧬 Code Graph Analysis (1)
stdlib/src/array.rs (2)
vm/src/builtins/memory.rs (2)
  • itemsize (582-584)
  • format (628-631)
vm/src/protocol/buffer.rs (1)
  • format (188-201)
🔇 Additional comments (6)
Cargo.toml (1)

141-141: Toolchain bump to 1.87.0 is appropriate for using is_multiple_of (incl. const contexts). LGTM.

This aligns the workspace with the new integer helpers used across the PR and should satisfy future clippy suggestions.

wtf8/src/core_str_count.rs (1)

38-38: Const-time divisibility check via is_multiple_of is correct.

This maintains the original invariant and compiles under the bumped toolchain.

stdlib/src/pystruct.rs (1)

174-175: Switch to is_multiple_of improves readability; semantics unchanged.

Zero-size is already rejected just above (Line 169), so there’s no behavioral risk here.

stdlib/src/array.rs (3)

854-856: Use of is_multiple_of for length/itemsize check is correct.

Matches prior behavior without modulo; clearer intent.


1476-1476: Big-endian bit via !code.is_multiple_of(2) is equivalent and clear.

No behavior change for u8; safe and explicit.


1618-1620: Divisibility check with is_multiple_of reads better; behavior unchanged.

Error path and message remain identical.

@youknowone youknowone merged commit bfc513e into RustPython:main Aug 20, 2025
12 checks passed
@youknowone youknowone deleted the fix-clippy branch August 20, 2025 08:34
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