Skip to content

fix(lint): replace drain(..).collect() with mem::take for clippy 1.98 - #171

Merged
cspinetta merged 2 commits into
mainfrom
fix/clippy-1.98-drain-collect
Aug 20, 2026
Merged

fix(lint): replace drain(..).collect() with mem::take for clippy 1.98#171
cspinetta merged 2 commits into
mainfrom
fix/clippy-1.98-drain-collect

Conversation

@cspinetta

Copy link
Copy Markdown
Member

Description

main is currently red on Lint (ubuntu-latest) and Lint (ubuntu-24.04-arm), and every open pull request fails the same way. Nothing in the code changed — the toolchain did.

GitHub's runners moved from rustc 1.97.1 to 1.98.0 (released 2026-08-18) on 2026-08-20. Rust 1.98 promoted clippy::drain_collect, and the lint job runs -D warnings against whatever stable resolves to, so three pre-existing sites began failing on the next run. main's last green CI run was 2026-08-19, on 1.97.1.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Changes Made

Three drain(..).collect() calls become std::mem::take:

  • src/devices/vsock_connection.rs — twice, handing a connection's queued guest-bound bytes to the caller
  • src/network/slirp.rs — once, taking the pending DNS queries before resolving them

Every site drains a Vec<T> into a Vec<T>. mem::take swaps in an empty vector and returns the original, which is observably identical — the source ends up empty either way — and skips the reallocation collect performs to rebuild a vector the source already held.

Testing

  • All existing tests pass (cargo test --workspace)

Test Commands Run

Verified on a Linux host after updating it to the same toolchain the runners now use, since neither of my machines could reproduce otherwise (one was on 1.97.1, the other on 1.94):

rustup update stable          # 1.97.1 -> 1.98.0 (88d9e12ae 2026-08-18)

# main, to confirm the breakage is pre-existing and not from this branch:
git checkout origin/main
cargo clippy --workspace --all-targets --all-features -- -D warnings
# → 3 errors: draining all elements of a collection into a new collection of the same type

# this branch:
cargo clippy --workspace --all-targets --all-features -- -D warnings   # clean
cargo test --workspace --all-features                                  # pass

Local validation

  • Host: Fedora x86_64 (dev1), rustc 1.98.0 — matching the runners
  • VM suites: not run (no VM, device, or runtime behavior changes; three expression-level rewrites with identical semantics)
  • Perf bench: not run. mem::take removes an allocation and a copy on each of these paths, so the change can only help; measuring it is not worth a bench run.
  • Security review: none (no behavior change)
  • Perf review: none

Code Quality

  • Code follows project style guidelines (cargo fmt)
  • No clippy warnings (cargo clippy --workspace --all-targets)

Additional Notes

This will recur. dtolnay/rust-toolchain@stable floats, so any Rust release can promote a lint that reddens every pull request at once, for code nobody touched — and it lands as a required-check failure rather than as a signal that a toolchain moved. Worth deciding separately whether the lint job should pin a version and bump it deliberately; I have not changed that here, since it is a policy question rather than part of unbreaking the build.

A second, smaller gap this exposed: contributors' machines can sit several releases behind the runners, so a local cargo clippy proves less than it appears to. Mine was on 1.94 (March) and the Linux validation host on 1.97.1; neither could reproduce a failure the gate had already hit.

Rust 1.98 promoted `clippy::drain_collect`, and the lint job runs `-D warnings` against whatever `stable` resolves to, so three pre-existing sites started failing the moment the runners moved from 1.97.1 to 1.98.0. Nothing in the code changed; the toolchain did.

`drain(..).collect()` into a collection of the same type reallocates to build a vector the source already held. `std::mem::take` swaps in an empty vector and hands back the original, which is observably identical — the source ends up empty either way — and skips the copy.

Two sites hand a connection's queued bytes to a caller in `vsock_connection`, and one takes the pending DNS queries in the SLIRP stack.
@cspinetta
cspinetta merged commit 43ac2ca into main Aug 20, 2026
22 checks passed
@cspinetta
cspinetta deleted the fix/clippy-1.98-drain-collect branch August 20, 2026 23: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