Support intra-doc links on cross-crate reexports #65983
Description
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 ofstd::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