Skip to content

Line indexes in Span are incorrectly claimed to be "zero indexed" #139906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fluiderson opened this issue Apr 16, 2025 · 1 comment · Fixed by #139919
Closed

Line indexes in Span are incorrectly claimed to be "zero indexed" #139906

fluiderson opened this issue Apr 16, 2025 · 1 comment · Fixed by #139919
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@fluiderson
Copy link

Location

Summary

echo "pub mod bbb {}" > aaa.rs;
RUSTC_BOOTSTRAP=1 rustdoc aaa.rs -Zunstable-options -wjson -o- |
jq '.index | map(select(.name == "bbb"))[0].span';
rm aaa.rs

outputs

{
  "filename": "aaa.rs",
  "begin": [
    1, // Not zero indexed.
    0
  ],
  "end": [
    1, // Not zero indexed.
    11
  ]
}
@fluiderson fluiderson added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Apr 16, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 16, 2025
@GuillaumeGomez GuillaumeGomez added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-json Area: Rustdoc JSON backend and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 16, 2025
@GuillaumeGomez
Copy link
Member

You're right, thanks for reporting it. Gonna fix the doc.

@bors bors closed this as completed in d49361a Apr 19, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 19, 2025
Rollup merge of rust-lang#139919 - GuillaumeGomez:rustdoc-json-1-indexed, r=aDotInTheVoid

Make rustdoc JSON Span column 1-based, just like line numbers

Fixes rust-lang#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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants