Closed
Description
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?
Metadata
Metadata
Assignees
Labels
Area: Intra-doc links, the ability to link to items in docs by nameArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Category: An issue proposing an enhancement or a PR with one.Issue: In need of a decision.Relevant to the rustdoc team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
jyn514 commentedon Jun 26, 2020
Isn't this expected behavior? Macros are always moved up to the crate root.
Lokathor commentedon Jun 26, 2020
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 commentedon 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 commentedon Jun 26, 2020
@rustbot modify labels: C-enhancement
Lokathor commentedon Jun 26, 2020
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.
crate
means something different when an item is re-exported #77193jyn514 commentedon Oct 9, 2020
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?
[-][rustdoc] intra-doc links for macros and functions have inconsistent rules.[/-][+][rustdoc] intra-doc links for macros always resolve relative to the crate root[/+]Manishearth commentedon Oct 9, 2020
@jyn514 I don't have a strong opinion here
10 remaining items