Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ fn make_code_region(
// Extend an empty span by one character so the region will be counted.
let CharPos(char_pos) = start_col;
if span.hi() == body_span.hi() {
start_col = CharPos(char_pos - 1);
start_col = CharPos(char_pos.saturating_sub(1));
Copy link
Member

@wesleywiser wesleywiser May 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should fix the rest of this function to use saturating math since it's not much code? Specifically, can we also fix the addition on lines 520, 531 and 533?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmandry - Do you mind doing that, if you agree it's worth it?

Sorry for the bug, but I thought lookup_file_pos() should never return less than 1. Maybe I misunderstood or the implementation changed, but that's not something the compiler would have enforced of course, so this is a good fix. Thanks.

} else {
end_col = CharPos(char_pos + 1);
}
Expand Down