From 2f02a4e4a02fed8275f71f800899fadc488b18d9 Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Tue, 24 May 2022 12:08:54 -0700 Subject: [PATCH] coverage: Don't underflow column number I noticed this when running coverage on a debug build of rustc. There may be other places that do this but I'm just fixing the one I hit. --- compiler/rustc_mir_transform/src/coverage/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index 2bb9f48f9b7c8..a96b8efd481a4 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -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)); } else { end_col = CharPos(char_pos + 1); }