Skip to content

Add lines labels to /crate/**/source/ #2551

Closed
@xFrednet

Description

@xFrednet

While generating some links, I noticed that source files under https://docs.rs/crate/{crate}/{version}/source/src/{file} don't support line labels. This is opposed to the sources under https://docs.rs/{crate}/{version}/src/{krate}/{file}.html#{line} that do.

Usually, I'd just use the second link with line label support for everything. However, rustdoc can sometimes remap paths, for example if a path is set in Cargo.toml. This means that the second link doesn't always work. At the end of the issue, I'll give a detailed example of this.

For my use case, the best solution would be to add line numbers and line labels to the sources under crate/{crate}/{version}/source/.

I'd be happy to give the implementation a shot, if this is something that would be accepted and I get some hints where to start 🗡️


Specific example:

We run Clippy in our CI and collect lint emissions. These diagnostics have paths as seen by rustc. It would, for example, look like this: ./src/lib.rs:15. I now want to take these file names and link to docs.rs to help us investigate the lint emissions. For most crates, the link is simply constructed like this:

  • https://docs.rs/{krate}/{version}/src/{krate}/{file}.html#{line}

And this works for most crates, expect crates that remap their path in Cargo.toml, like this (Taken from rust-lang/cargo):

[lib]
name = "cargo"
path = "src/cargo/lib.rs"

The lint emission then has the path ./src/cargo/lib.rs but the documentation generated by rustdoc removes the cargo from the path. So using the previous link template generates:

This doesn't work due to the cargo/cargo. The correct link with the remapped path is:

This remapping only happens for rustdoc and not the source files under crate/ so if those would support line labels, it would be a simple way to always use the same link template.

Metadata

Metadata

Assignees

Labels

A-frontendArea: Web frontendE-easyEffort: Should be easy to implement and would make a good first PR

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions