about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorChris Denton <chris@chrisdenton.dev>2025-04-19 14:01:38 +0000
committerGitHub <noreply@github.com>2025-04-19 14:01:38 +0000
commitd49361a79871602b40182790d7dd064ece1d3c5d (patch)
tree780ecab05ef7106a06b3eb61a62a86c88fbddd16 /src
parentdff14f06341309b7edf3e760ab9762175db322f3 (diff)
parent076016d55afdf760c7e30e23c5df8f0c079cd85b (diff)
downloadrust-d49361a79871602b40182790d7dd064ece1d3c5d.tar.gz
rust-d49361a79871602b40182790d7dd064ece1d3c5d.zip
Rollup merge of #139919 - GuillaumeGomez:rustdoc-json-1-indexed, r=aDotInTheVoid
Make rustdoc JSON Span column 1-based, just like line numbers

Fixes https://github.com/rust-lang/rust/issues/139906.

This PR does two things:
 1. It makes column 1-indexed as well, just like lines.
 2. It updates documentation about them to mention that they are 1-indexed.

I think it's better for coherency to have them both 1-indexed instead of the weird mix we used to have. Docs for `line` and `col` fields can be found [here](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Loc.html#structfield.line).

And finally: it adds a regression test to ensure they are indeed 1-indexed.

r? `@aDotInTheVoid`
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/json/conversions.rs4
-rw-r--r--src/rustdoc-json-types/lib.rs6
2 files changed, 5 insertions, 5 deletions
diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs
index dab23f8e42a..f446c9fbbd8 100644
--- a/src/librustdoc/json/conversions.rs
+++ b/src/librustdoc/json/conversions.rs
@@ -84,8 +84,8 @@ impl JsonRenderer<'_> {
                     let lo = span.lo(self.sess());
                     Some(Span {
                         filename: local_path,
-                        begin: (lo.line, lo.col.to_usize()),
-                        end: (hi.line, hi.col.to_usize()),
+                        begin: (lo.line, lo.col.to_usize() + 1),
+                        end: (hi.line, hi.col.to_usize() + 1),
                     })
                 } else {
                     None
diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs
index 7247950545a..64223b5b758 100644
--- a/src/rustdoc-json-types/lib.rs
+++ b/src/rustdoc-json-types/lib.rs
@@ -30,7 +30,7 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
 /// This integer is incremented with every breaking change to the API,
 /// and is returned along with the JSON blob as [`Crate::format_version`].
 /// Consuming code should assert that this value matches the format version(s) that it supports.
-pub const FORMAT_VERSION: u32 = 44;
+pub const FORMAT_VERSION: u32 = 45;
 
 /// The root of the emitted JSON blob.
 ///
@@ -205,9 +205,9 @@ pub struct Item {
 pub struct Span {
     /// The path to the source file for this span relative to the path `rustdoc` was invoked with.
     pub filename: PathBuf,
-    /// Zero indexed Line and Column of the first character of the `Span`
+    /// One indexed Line and Column of the first character of the `Span`.
     pub begin: (usize, usize),
-    /// Zero indexed Line and Column of the last character of the `Span`
+    /// One indexed Line and Column of the last character of the `Span`.
     pub end: (usize, usize),
 }