Skip to content

[rustdoc] intra-doc links for macros always resolve relative to the crate root #72243

Closed
@Lokathor

Description

@Lokathor
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?

Activity

added
A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by name
T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
on May 15, 2020
jyn514

jyn514 commented on Jun 26, 2020

@jyn514
Member

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

Lokathor commented on Jun 26, 2020

@Lokathor
ContributorAuthor

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

jyn514 commented on Jun 26, 2020

@jyn514
Member

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

jyn514 commented on Jun 26, 2020

@jyn514
Member

@rustbot modify labels: C-enhancement

added
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Jun 26, 2020
Lokathor

Lokathor commented on Jun 26, 2020

@Lokathor
ContributorAuthor

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.

added
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
on Oct 9, 2020
jyn514

jyn514 commented on Oct 9, 2020

@jyn514
Member

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?

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[/+] on Oct 9, 2020
Manishearth

Manishearth commented on Oct 9, 2020

@Manishearth
Member

@jyn514 I don't have a strong opinion here

10 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by nameA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-needs-decisionIssue: In need of a decision.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Manishearth@jonas-schievink@jhpratt@ChrisDenton@Lokathor

        Issue actions

          [rustdoc] intra-doc links for macros always resolve relative to the crate root · Issue #72243 · rust-lang/rust