perf: Fix clippy::drain_collect - #8500
Conversation
📝 WalkthroughWalkthroughThe PR simplifies ChangesTail-call reference ownership
Code-page error handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/vm/src/vm/mod.rs`:
- Line 1471: Replace the remaining pending tail-call reference
`.drain(..).collect()` in the exception-unwind tail-call branch with the same
`mem::take` ownership transfer used by `initial_refs` and the analogous
branches. Preserve the existing behavior and run `cargo clippy` afterward.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro Plus
Run ID: 34fd5b4d-baa6-4d5c-b1e3-c931476ab6a6
📒 Files selected for processing (2)
crates/vm/src/stdlib/_codecs.rscrates/vm/src/vm/mod.rs
| let initial_refs = unsafe { &mut *self.pending_tailcall_refs.get() } | ||
| .drain(..) | ||
| .collect(); | ||
| let initial_refs = mem::take(unsafe { &mut *self.pending_tailcall_refs.get() }); |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
if rg -n -U '\.drain\(\.\.\)\s*\.collect\(\)' crates/vm/src/vm/mod.rs; then
echo "A drain(..).collect() call remains." >&2
exit 1
fiRepository: RustPython/RustPython
Length of output: 308
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- relevant source ---'
sed -n '1450,1565p' crates/vm/src/vm/mod.rs
sed -n '1585,1625p' crates/vm/src/vm/mod.rs
printf '%s\n' '--- all drain(..).collect() patterns in the file ---'
rg -n -U -C 2 '\.drain\(\.\.\)\s*\.collect\(\)' crates/vm/src/vm/mod.rs || true
printf '%s\n' '--- mem::take usage and pending-tailcall references ---'
rg -n -C 2 'pending_tailcall_refs|mem::take' crates/vm/src/vm/mod.rsRepository: RustPython/RustPython
Length of output: 10658
Replace the remaining .drain(..).collect() call with mem::take.
The exception-unwind tail-call branch still uses this pattern at lines 1607–1609. Apply the same ownership transfer used at lines 1471, 1500, and 1548, then run cargo clippy.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/vm/src/vm/mod.rs` at line 1471, Replace the remaining pending
tail-call reference `.drain(..).collect()` in the exception-unwind tail-call
branch with the same `mem::take` ownership transfer used by `initial_refs` and
the analogous branches. Preserve the existing behavior and run `cargo clippy`
afterward.
Source: Coding guidelines
Summary
I noticed this lint while fixing up my last patch. It seems reasonable, but I'll rely on CodeRabbit to check if it's spurious in which case I'll just
expectthe lint.Summary by CodeRabbit