Rustdoc currently creates a copy of the resolver to use for intra-doc links:
|
crate fn create_resolver<'a>( |
|
externs: config::Externs, |
|
queries: &Queries<'a>, |
|
sess: &Session, |
|
) -> Rc<RefCell<interface::BoxedResolver>> { |
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:
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?
|
let resolver = peeked.1.steal(); |
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
Rustdoc currently creates a copy of the resolver to use for intra-doc links:
rust/src/librustdoc/core.rs
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:
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) ?
Would it be possible for
lower_to_hirto 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().1whenever it needs access to the resolver.See #68427 for previous discussion.
Implementation History
clean::Items before resolving intra-doc links: rustdoc: Store intra-doc links in Cache instead of on items directly #83833collect_intra_doc_links: rustdoc: Move crate loader to collect_intra_doc_links::early #84101preprocess_linkto also take into account the hacks forSelf::andcrate:rust/src/librustdoc/passes/collect_intra_doc_links.rs
Line 880 in ef52471
rust/src/librustdoc/passes/collect_intra_doc_links.rs
Lines 1124 to 1153 in ef52471