Repository navigation
fix: remove #[must_use] from Drain - #486
Merged
Merged
Conversation
`CompactString::drain` removes the selected range in `Drain`'s `Drop` impl, so `drain(range)` is a valid and common way to just delete a range without consuming the returned iterator. Marking `Drain` as `#[must_use]` wrongly warned on that pattern; `alloc::string::Drain` isn't `must_use` for the same reason. Also adds the previously-missing drain test coverage, including the drop-without-consuming path (inline + heap), partial-consume-then-drop removing the full range, multi-byte boundaries, and a proptest asserting parity with `String::drain` for both the consumed and dropped cases. Closes #435. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ParkMyCar
enabled auto-merge (squash)
July 12, 2026 03:15
test_drain_without_consuming_removes_range_inline used a 13-byte string and asserted it wasn't heap allocated, but MAX_SIZE is only 12 on 32-bit targets, so the string was heap allocated there and the assertion failed. Use a 9-byte string that stays inline on both 32- and 64-bit. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VGTA38KYXfd6EgVAiUYJ1e
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.
Closes #435.
Drainwas marked#[must_use = "iterators are lazy and do nothing unless consumed"], but that's misleading here: dropping aDrainstill removes the selected range from the sourceCompactString(that's what itsDropimpl does), sodrain(range)purely to delete a range — without consuming the iterator — is a valid and common use.alloc::string::Drainisn't#[must_use]for exactly this reason.This removes the attribute and documents why it's deliberately absent. Adds tests covering drain-without-consuming (inline and heap), partial consumption still removing the full range, the yielded characters, empty/full ranges, a multibyte boundary, and a proptest comparing against
String::drain.