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] intra-doc links for macros always resolve relative to the crate root #72243

Closed
Lokathor opened this issue May 15, 2020 · 13 comments
Closed
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one. I-needs-decision Issue: In need of a decision. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Lokathor
Copy link
Contributor

If you have a function defined within a module it will use that module's imports to determine link resolution for intra-doc links in the documentation.

If you do the same with a macro, it seems to "scope" the macro (and thus its intra-doc links) at the crate root only, so the macro's documentation can't benefit from the local imports.

This feels inconsistent, and can it be fixed so that macro intra-links get the local imports for their resolution?

@jonas-schievink jonas-schievink added A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels May 15, 2020
@jyn514
Copy link
Member

jyn514 commented Jun 26, 2020

it seems to "scope" the macro (and thus its intra-doc links) at the crate root only,

Isn't this expected behavior? Macros are always moved up to the crate root.

@Lokathor
Copy link
Contributor Author

Logically, within the crate's namespace, yes, the macro will appear in the crate root.

However, it makes editing the docs of the macro worse because the macro's actual location is still whatever file it's written in, not always lib.rs. Every other item's docs use the local file's imports to determine intra-doc links.

@jyn514
Copy link
Member

jyn514 commented Jun 26, 2020

Technically they use the imports of the parent module, not the imports of the current file. I'm sympathetic to this use case but I'm not sure how feasible it is to implement, by the time rustdoc resolves intra-doc links we've lost the lexical scope and we're left with only the DefId (resolution scope): https://github.com/rust-lang/rust/blob/master/src/librustdoc/passes/collect_intra_doc_links.rs#L428

@jyn514
Copy link
Member

jyn514 commented Jun 26, 2020

@rustbot modify labels: C-enhancement

@rustbot rustbot added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jun 26, 2020
@Lokathor
Copy link
Contributor Author

Well if it can't be done it's ultimately fine, it just hit me as a weird detail on a crate that has many macros which must be kept in many separate files.

@jyn514 jyn514 added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Oct 9, 2020
@jyn514
Copy link
Member

jyn514 commented Oct 9, 2020

I'm not sure how feasible it is to implement, by the time rustdoc resolves intra-doc links we've lost the lexical scope and we're left with only the DefId

After #77519 this is no longer true; I don't think we currently store the scope if it's not a re-exports, but it shouldn't be too hard to add. So this changes to a question of whether we should change it.

@Manishearth what do you think?

@jyn514 jyn514 changed the title [rustdoc] intra-doc links for macros and functions have inconsistent rules. [rustdoc] intra-doc links for macros always resolve relative to the crate root Oct 9, 2020
@jyn514 jyn514 added the I-needs-decision Issue: In need of a decision. label Oct 9, 2020
@Manishearth
Copy link
Member

@jyn514 I don't have a strong opinion here

@jhpratt

This comment has been minimized.

@jyn514

This comment has been minimized.

@jhpratt

This comment has been minimized.

@jyn514

This comment has been minimized.

@jyn514
Copy link
Member

jyn514 commented Dec 30, 2020

Since intra-doc links are already stable, and since this is following the same rules of the language, we do not plan to change the behavior here.

@jyn514 jyn514 closed this as completed Dec 30, 2020
@ChrisDenton
Copy link
Member

ChrisDenton commented Mar 27, 2021

In that case, is there a way to force linking to a macro in a specific path instead of resolving to the crate root? I'm finding it makes some docs weird when the text says one thing but the link goes somewhere else.

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 A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one. I-needs-decision Issue: In need of a decision. 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

7 participants