fixed VecDeque::splice() not filling the buffer correctly when resizing the buffer on start = end range#152258
Open
asder8215 wants to merge 1 commit intorust-lang:mainfrom
Open
fixed VecDeque::splice() not filling the buffer correctly when resizing the buffer on start = end range#152258asder8215 wants to merge 1 commit intorust-lang:mainfrom
asder8215 wants to merge 1 commit intorust-lang:mainfrom
Conversation
Collaborator
|
|
This comment has been minimized.
This comment has been minimized.
d33db94 to
2ecddd2
Compare
joboet
requested changes
Feb 7, 2026
Collaborator
|
Reminder, once the PR becomes ready for a review, use |
asder8215
commented
Feb 7, 2026
65cec58 to
748d3c1
Compare
Contributor
Author
|
@rustbot ready |
joboet
requested changes
Feb 12, 2026
joboet
requested changes
Feb 21, 2026
440a328 to
409bb2f
Compare
Member
|
Looks great, thank you! Could you squash your commits, please? I'll approve after that. |
409bb2f to
bb67ee2
Compare
Contributor
Author
|
@joboet put the change into one commit. Lmk if there's anything else I need to do! |
joboet
requested changes
Feb 28, 2026
…ng the buffer on start = end range
bb67ee2 to
d0a33ab
Compare
Contributor
Author
|
Hope the new comment/rationale on the change is okay! |
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.
This PR fixes #151758. The issue came from
Splice::move_tail, which as joboet pointed out:The problem with reserving more space through
VecDeque'sbuf.reserve()is that it doesn't updateVecDeque'shead, which means that this code inmove_tail:could move over the section of data that
tail_start..tail_start + self.tail_lenof the buffer is supposed to be held at to the incorrect destination since all.to_physical_idx()is doing is a wrapping add on theVecDeque's head with the passed inidxvalue.To avoid this I decided to use
VecDeque::reserveto both allocate more space into theVecDequeif necessary and update head appropriately. However,VecDeque::reserveinternally relies on theVecDeque'slenfield. Earlier inVecDeque::splice, it modifies theVecDeque'slenconstructing the drain viaDrain::new(as it does amem::replaceondeque.lenwith the start bound of the passed inrange). TheVecDeque'slencan also be potentially modified in the earlierSplice::fill()call if it does any replacement towards elements within the passed inrangevalue forVecDeque::splice(). I needed to temporarily restore theVecDeque'slento its actual len, so thatVecDeque::reservecan work properly. Afterward, you can bring back theVecDeque'slento what its value was before and fill the gap appropriately with the rest of thereplace_withcontent.r? @joboet