Description
Rustdoc currently creates a copy of the resolver to use for intra-doc links:
Lines 350 to 354 in d474075
This is a Terrible, Horrible, No Good, Very Bad Idea. In particular, it causes rustdoc's copy of the resolver and the TyCtxt to disagree about what crates exist:
- ICE when documenting code with intra-doc-links with types with the same name but different crates #66159 (comment)
- Fix intra-doc links for cross-crate re-exports of default trait methods #75176
- Fix impl being removed excessively #82496 (comment)
It's also distorting rustc_resolve, since not all of the outputs make sense to clone in the first place: #65625 (comment)
We should refactor rustdoc somehow to allow getting rid of Resolver::clone_outputs
. @petrochenkov suggests moving anything that needs to touch the resolver before HIR lowering: #68427 (comment).
@petrochenkov what do you think about @eddyb's comment in #65625 (comment) ?
Why would cloning be needed? Is this that support for resolving things after rustc_resolve finishes?
In that case I'm not sure why we need to clone the outputs - is it to be able to keep the original resolver around?
Would it be possible for lower_to_hir
to stop stealing the resolver?
rust/compiler/rustc_interface/src/queries.rs
Line 227 in d474075
Then rustdoc wouldn't need to clone it in the first place, it could just call queries.expansion().peek().1
whenever it needs access to the resolver.
See #68427 for previous discussion.
Implementation History
- Initial "early crate loader": rustdoc: Don't load all extern crates unconditionally #83738
- Don't require
clean::Item
s before resolving intra-doc links: rustdoc: Store intra-doc links in Cache instead of on items directly #83833 - Separate type-relative resolution from path resolution (at least somewhat): rustdoc: Cleanup handling of associated items for intra-doc links #83849
- Move early loader into
collect_intra_doc_links
: rustdoc: Move crate loader to collect_intra_doc_links::early #84101 - Move all path resolution from late to early module and add new field on DocContext for partially resolved links
- Change
preprocess_link
to also take into account the hacks forSelf::
andcrate
: ,rust/src/librustdoc/passes/collect_intra_doc_links.rs
Lines 1124 to 1153 in ef52471
- Change