Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

fix insert at beginning #224

Merged
merged 2 commits into from Nov 19, 2023
Merged

fix insert at beginning #224

merged 2 commits into from Nov 19, 2023

Conversation

dnbln
Copy link
Contributor

@dnbln dnbln commented Nov 8, 2023

Previously trying to insert some code at the very beginning seems to have caused issues.

Using start=0, end=0 means "replace the first character with the given data", so to properly insert at the beginning the code should call .replace_range(0, -1, b"...") (not possible because -1 is not an usize). This commit fixes that by using exclusive ranges instead, so now .replace_range(0..0, b"...") inserts at the beginning.

Copy link
Collaborator

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I agree that all the saturating_sub stuff was a bit of a mess, and using exclusive seems to make more sense (and matches the JSON output, too). I'm a little uneasy since it can be difficult to reason about all the edge cases, but I don't see anything particularly concerning. Also, I ran it through the rustc testsuite and it seemed to be ok (though that is an unfortunately small set).

@ehuss ehuss merged commit ae377f7 into rust-lang:master Nov 19, 2023
3 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants