Skip to content

Support intra-doc links on cross-crate reexports #65983

Closed
@Manishearth

Description

Previously: #60883, #59833

This is the last major issue blocking the stabilization of intra doc links (#43466)

Currently, if you use intra-doc links on some item:

// crate "foo"

/// This is not [Baz]
pub struct Bar;

pub struct Baz;

the docs will not turn up on any crate reexporting it

pub use foo::Bar;

The docs will have a bare [Baz] instead of the appropriate intra-doc link, because we resolve intra-doc links locally. (More examples in #60883, #59833)


This is tricky to fix; we throw away module resolution information before packaging up crate metadata, so it's not possible to "unseal" a crate and rerun the resolution within it. One solution would be to pre-detect intra doc links and store resolutions in metadata, but this would be expensive since it involves parsing everything as markdown unconditionally.

A better solution is to save resolution information in the metadata, as some kind of tree keyed to the module.

@eddyb's comment outlines the correct approach to use here

What you actually want to persist cross-crate is the scope information that lets you resolve names in a certain (module) scope, after the fact. It'd also allow not doing all the the resolver hacks.

And there's a very good reason to want it in the compiler, at least same-crate: we could (finally) tell if a type is in scope somewhere so we can actually print Vec<_> instead of std::vec::Vec<_> etc.

Basically, instead of throwing away resolver metadata, we should serialize it into some form and store it in the metadata, so that it can be reloaded as necessary.

Activity

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

Metadata

Assignees

No one assigned

    Labels

    A-cross-crate-reexportsArea: Documentation that has been re-exported from a different crateA-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by nameC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.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

    Issue actions