-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I have been looking through the source of rustc_span and stumbled upon an inconsistent usage of byte positions.
The problematic code is from SourceFile::normalized_byte_pos:
self
.normalized_pos
.binary_search_by(|np| (np.pos.0 + np.diff).cmp(&(self.start_pos.0 + offset)))Here offset is a byte offset relative to the start of the file. The problem is, that NormalizedPos contains a relative byte pos, but we are comparing it with an absolute one. The current definition of NormalizedPos is the following:
pub struct NormalizedPos {
/// The relative offset of the character in the `SourceFile`.
pub pos: RelativeBytePos,
/// The difference between original and normalized string at position.
pub diff: u32,
}When the method normalized_byte_pos was introduced(bba2a1e) the NormalizedPos used an absolute byte pos. But it was later to changed to use relative byte pos in 258ace6
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.