From fc36af302b25b79cf3d1798e2c584a2df03c9036 Mon Sep 17 00:00:00 2001 From: Bryan Malyn Date: Mon, 18 Aug 2025 19:00:05 -0500 Subject: [PATCH] Omit line number for toml parse error for unknown spans In the case that the span is (0..0), we don't usually know where the error really occurred. In that case just omit the line number. Resolves: #2189 This error is tracked upstream: * toml: https://github.com/toml-rs/toml/issues/589 * serde: https://github.com/serde-rs/serde/issues/1183 --- src/util.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/util.rs b/src/util.rs index eaadce60a8..339130c290 100644 --- a/src/util.rs +++ b/src/util.rs @@ -99,11 +99,15 @@ where let location_msg = err .span() .map(|span| { - let line = 1 + contents.as_bytes()[..(span.start)] - .iter() - .filter(|b| **b == b'\n') - .count(); - format!(" at line {line}") + if span == (0..0) { + String::new() + } else { + let line = 1 + contents.as_bytes()[..(span.start)] + .iter() + .filter(|b| **b == b'\n') + .count(); + format!(" at line {line}") + } }) .unwrap_or_default(); Error::new(format!(