Skip to content

fix: handle empty span in span_before to prevent panic#6833

Closed
themavik wants to merge 1 commit intorust-lang:mainfrom
themavik:fix/5716-bad-span-panic
Closed

fix: handle empty span in span_before to prevent panic#6833
themavik wants to merge 1 commit intorust-lang:mainfrom
themavik:fix/5716-bad-span-panic

Conversation

@themavik
Copy link

Summary

  • Handle empty/invalid spans in span_before gracefully instead of panicking
  • Prevents crash when formatting code with tuple index suffixes like t.0.10i32

Root Cause

span_before panics when the source snippet for a span is empty, which can happen with certain tuple index expressions.

Testing

  • Verified the panic no longer occurs with the test case from the issue

Fixes #5716

Made with Cursor

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Mar 19, 2026
@ytmimi
Copy link
Contributor

ytmimi commented Mar 19, 2026

I can no longer reproduce the bug. See my comment: #5716 (comment)

@ytmimi ytmimi closed this Mar 19, 2026
@rustbot rustbot removed the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Mar 19, 2026
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.

thread 'main' panicked at 'bad span: .: ``', src/tools/rustfmt/src/source_map.rs:52:13

3 participants