Conversation
…on tests Writing regression tests for the byte-vs-char fix surfaced a residual off-by-one present in both the original code and the fix: the line counter incremented before the offset comparison, so a finding whose next character is a newline (e.g. a one-character identifier at end of line) was reported one line late. Counting newlines strictly before the offset removes the iteration-order subtlety entirely. Tests cover ASCII offsets, multi-byte content before the offset (was reported lines late), a byte offset beyond the file's char count (was an unreachable! panic), and offsets at EOF.
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.
Problem
offset_to_lineinsrc/check/utils.rsconverts a finding's source location to a line number for display. It iteratedcontent.chars().enumerate()— character indices — but compared them againststart, which comes from solangLocs and is a byte offset. The two only coincide for pure-ASCII files, which is why this went unnoticed.For files containing multi-byte UTF-8 (emoji, non-Latin comments), there are two symptoms:
unreachable!("content.len() > start"), crashing the entirescopelint checkrun:// 🚀🚀🚀...(300 emoji) comment followed by a naming violation.Fix
Iterate with
char_indices()instead, which yields byte offsets, making the comparison byte-to-byte. Thedebug_assert!/unreachable!are replaced with a defensive fallback returning the last line whenstartis at or past EOF.This was the only
chars().enumerate()offset comparison in the codebase — other modules (e.g.inline_config.rs) already usechar_indices()correctly.