Skip to content
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

Rustdoc links items in the standard library to the original crate, not the re-export #78467

Closed
Evian-Zhang opened this issue Oct 28, 2020 · 7 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Evian-Zhang
Copy link

In my docs, I use [`String`] or even [`std::string::String`], I expect the generated link is to the std page, but the generated link is to the alloc page.

I know maybe std re-exports some structs in alloc, core, etc. but for a beginner who does not know well about rust, he may be confused when clicking the link to String and get an unfamiliar path. So what can I do if I want to link to std page?

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (a1dfd2490 2020-10-05)
binary: rustc
commit-hash: a1dfd2490a6cb456b92e469fa550dc217e20ad6d
commit-date: 2020-10-05
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly
LLVM version: 11.0
@Evian-Zhang Evian-Zhang added the C-bug Category: This is a bug. label Oct 28, 2020
@jyn514 jyn514 added A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Oct 28, 2020
@jyn514
Copy link
Member

jyn514 commented Oct 28, 2020

This is not really supported by intra-doc links. How should it know which re-exports are canonical and which are not? The best it can do is the original place the item was defined.

@camelid
Copy link
Member

camelid commented Oct 28, 2020

Perhaps we could add some kind of attribute to a re-export (something like #[canonical] or #[rustdoc_canonical]) but I don't think it's necessarily worth it.

@jyn514
Copy link
Member

jyn514 commented Oct 28, 2020

Note that this is not specific to intra-doc links, if you have a function returning string, rustdoc will also link to alloc, not std.

@jyn514 jyn514 removed the A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name label Oct 28, 2020
@jyn514 jyn514 changed the title Intra-doc links do not link to std page. Rustdoc links items in the standard library to the original crate, not the re-export Oct 28, 2020
@Nemo157
Copy link
Member

Nemo157 commented Oct 28, 2020

Is the data used to decide when to inline the docs available during intra-doc links (#[doc(inline)] + whatever makes it implicitly inline)? If rustdoc knows which re-export was used in a particular link (and other locations), and has that data available, it seems like the inlining of the docs matches up with when you would want to link to the inlined docs instead of the original location.

@jyn514
Copy link
Member

jyn514 commented Oct 28, 2020

This logic is done by fn href:

pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {

In particular, if it's not in cache.paths, it always looks in the original crate:
match cache.extern_locations[&did.krate] {

I don't know what causes something to be in paths or extern_locations.

@jyn514
Copy link
Member

jyn514 commented Nov 4, 2020

This is actually a duplicate of #22083.

@jyn514
Copy link
Member

jyn514 commented Apr 8, 2021

Is the data used to decide when to inline the docs available during intra-doc links (#[doc(inline)] + whatever makes it implicitly inline)?

This logic is done by fn href:

So no: #82014 (comment)

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants