Skip to content

Conversation

Muscraft
Copy link
Member

I came across rust-lang/rust-clippy#15883, which reported incorrect line numbers for a multi-line suggestion. I realized the incorrect line numbers were coming from rustc, which made me realize that annotate-snippets also had this problem.

The root cause of the problems comes from the process of trimming Patch's replacement to be a substring of the original. During this process, the span also gets adjusted to match the trimmed replacement. We later use this span to get the line_start when rendering the suggestion. This is where the bug happens: if the adjusted span's line_start does not match the original span's line_start, we would show incorrect line numbers.

To fix this, I made it so we track both the original span and trimmed span for Patchs, and use the original span for line_start.

@epage epage merged commit 7edacbb into rust-lang:master Oct 19, 2025
15 checks passed
@Muscraft Muscraft deleted the fix-trimmed-multiline-suggestions branch October 20, 2025 04:30
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.

2 participants