Skip to content

Fix panic in replace#398

Merged
epage merged 3 commits intorust-lang:mainfrom
Muscraft:fix-panic-in-replace
Apr 4, 2026
Merged

Fix panic in replace#398
epage merged 3 commits intorust-lang:mainfrom
Muscraft:fix-panic-in-replace

Conversation

@Muscraft
Copy link
Copy Markdown
Member

@Muscraft Muscraft commented Apr 4, 2026

When replace is passed a string whose length is greater than end - start, it would cause the drain on the line to panic as the range start was bigger than the range end. To address this, I switched from using drain and adding chars to using splice, as it does what the code intended.

While looking into this, I also realized the true cause was that we were trying to trim the middle of spans that were too short to trim, and decided to fix that as well.

Fixes #391

@epage epage merged commit 4ab53f1 into rust-lang:main Apr 4, 2026
15 of 16 checks passed
@Muscraft Muscraft deleted the fix-panic-in-replace branch April 4, 2026 01:05
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.

StyledBuffer::replace panics when term_width is 0 or very small

2 participants