Skip to content

rustdoc: Resolve some more doc links early 2 #96713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions src/librustdoc/passes/collect_intra_doc_links/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,34 +172,50 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
}

fn resolve_doc_links_extern_impl(&mut self, def_id: DefId, is_inherent: bool) {
self.resolve_doc_links_extern_outer(def_id, def_id);
self.resolve_doc_links_extern_outer_fixme(def_id, def_id);
let assoc_item_def_ids = Vec::from_iter(
self.resolver.cstore().associated_item_def_ids_untracked(def_id, self.sess),
);
for assoc_def_id in assoc_item_def_ids {
if !is_inherent || self.resolver.cstore().visibility_untracked(assoc_def_id).is_public()
{
self.resolve_doc_links_extern_outer(assoc_def_id, def_id);
self.resolve_doc_links_extern_outer_fixme(assoc_def_id, def_id);
}
}
}

fn resolve_doc_links_extern_outer(&mut self, def_id: DefId, scope_id: DefId) {
// FIXME: replace all uses with `resolve_doc_links_extern_outer` to actually resolve links, not
// just add traits in scope. This may be expensive and require benchmarking and optimization.
fn resolve_doc_links_extern_outer_fixme(&mut self, def_id: DefId, scope_id: DefId) {
if !self.resolver.cstore().may_have_doc_links_untracked(def_id) {
return;
}
// FIXME: actually resolve links, not just add traits in scope.
if let Some(parent_id) = self.resolver.opt_parent(scope_id) {
self.add_traits_in_scope(parent_id);
}
}

fn resolve_doc_links_extern_outer(&mut self, def_id: DefId, scope_id: DefId) {
if !self.resolver.cstore().may_have_doc_links_untracked(def_id) {
return;
}
let attrs = Vec::from_iter(self.resolver.cstore().item_attrs_untracked(def_id, self.sess));
let parent_scope = ParentScope::module(
self.resolver.get_nearest_non_block_module(
self.resolver.opt_parent(scope_id).unwrap_or(scope_id),
),
self.resolver,
);
self.resolve_doc_links(doc_attrs(attrs.iter()), parent_scope);
}

fn resolve_doc_links_extern_inner(&mut self, def_id: DefId) {
if !self.resolver.cstore().may_have_doc_links_untracked(def_id) {
return;
}
// FIXME: actually resolve links, not just add traits in scope.
self.add_traits_in_scope(def_id);
let attrs = Vec::from_iter(self.resolver.cstore().item_attrs_untracked(def_id, self.sess));
let parent_scope = ParentScope::module(self.resolver.expect_module(def_id), self.resolver);
self.resolve_doc_links(doc_attrs(attrs.iter()), parent_scope);
}

fn resolve_doc_links_local(&mut self, attrs: &[ast::Attribute]) {
Expand Down Expand Up @@ -253,9 +269,16 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
}
}

// FIXME: Resolve all prefixes for type-relative resolution or for diagnostics.
if (need_assoc || !any_resolved) && pinfo.path_str.contains("::") {
need_traits_in_scope = true;
// Resolve all prefixes for type-relative resolution or for diagnostics.
if need_assoc || !any_resolved {
let mut path = &pinfo.path_str[..];
while let Some(idx) = path.rfind("::") {
path = &path[..idx];
need_traits_in_scope = true;
for ns in [TypeNS, ValueNS, MacroNS] {
self.resolve_and_cache(path, ns, &parent_scope);
}
}
}
}
}
Expand Down