Skip to content

Rustdoc fails to translate Rust paths into URLs for non-inline links in footnotes #132208

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
taylordotfish opened this issue Oct 27, 2024 · 1 comment · Fixed by #134432
Closed
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@taylordotfish
Copy link

Rustdoc incorrectly renders non-inline links (those whose destinations are defined in link reference definitions) if the link occurs in a footnote and points to a Rust item. Rather than translating the Rust path into the corresponding documentation URL, the path is simply emitted verbatim as the link's href.

Example

With the following in src/lib.rs:

//! [a]: std::vec::Vec
//!
//! link in body: [a]
//!
//! see footnote[^1]
//!
//! [^1]: link in footnote: [a]

cargo doc produces the following HTML:

<p>link in body: <a href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">a</a></p>
<p>see footnote<sup id="fnref1"><a href="#fn1">1</a></sup></p>
<div class="footnotes"><hr><ol><li id="fn1"><p>link in footnote: <a href="std::vec::Vec">a</a>&nbsp;<a href="#fnref1"></a></p></li></ol></div>

The first link correctly leads to Vec's HTML documentation, but the second link is rendered literally as <a href="std::vec::Vec">.

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (c1db4dc24 2024-10-25)
binary: rustc
commit-hash: c1db4dc24267a707409c9bf2e67cf3c7323975c8
commit-date: 2024-10-25
host: powerpc64le-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1
@taylordotfish taylordotfish added the C-bug Category: This is a bug. label Oct 27, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 27, 2024
@taylordotfish
Copy link
Author

It appears that this issue also applies to inline links of the form [a](std::vec::Vec), but not [a][std::vec::Vec] or [`std::vec::Vec`].

@fmease fmease added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 27, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Dec 17, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 18, 2024
…tes, r=notriddle

Fix intra doc links not generated inside footnote definitions

Fixes rust-lang#132208.

The problem was that we were running the `Footnote` "pass" before the `LinkReplacer` one. Sadly, the change is bigger than it should because we can't specialize the `Iterator` trait implementation, forcing me to add a new type to handle the other `Iterator` kind (the one which still has the `Range`).

r? `@notriddle`
@bors bors closed this as completed in bd6ed18 Dec 19, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 19, 2024
Rollup merge of rust-lang#134432 - GuillaumeGomez:intra-doc-in-footnotes, r=notriddle

Fix intra doc links not generated inside footnote definitions

Fixes rust-lang#132208.

The problem was that we were running the `Footnote` "pass" before the `LinkReplacer` one. Sadly, the change is bigger than it should because we can't specialize the `Iterator` trait implementation, forcing me to add a new type to handle the other `Iterator` kind (the one which still has the `Range`).

r? ``@notriddle``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-bug Category: This is a bug. 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