fix(lint): replace drain(..).collect() with mem::take for clippy 1.98 - #171
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
mainis currently red onLint (ubuntu-latest)andLint (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 warningsagainst whateverstableresolves 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
Changes Made
Three
drain(..).collect()calls becomestd::mem::take:src/devices/vsock_connection.rs— twice, handing a connection's queued guest-bound bytes to the callersrc/network/slirp.rs— once, taking the pending DNS queries before resolving themEvery site drains a
Vec<T>into aVec<T>.mem::takeswaps in an empty vector and returns the original, which is observably identical — the source ends up empty either way — and skips the reallocationcollectperforms to rebuild a vector the source already held.Testing
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):
Local validation
mem::takeremoves an allocation and a copy on each of these paths, so the change can only help; measuring it is not worth a bench run.Code Quality
cargo fmt)cargo clippy --workspace --all-targets)Additional Notes
This will recur.
dtolnay/rust-toolchain@stablefloats, 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 clippyproves 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.