Skip to content
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

rustdoc: Resolve doc links in external traits having local impls #104364

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,11 @@ impl<'a> Resolver<'a> {
}
}

/// For rustdoc.
pub fn get_partial_res(&self, node_id: NodeId) -> Option<PartialRes> {
self.partial_res_map.get(&node_id).copied()
}

/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
#[inline]
pub fn opt_span(&self, def_id: DefId) -> Option<Span> {
Expand Down
9 changes: 8 additions & 1 deletion src/librustdoc/passes/collect_intra_doc_links/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,14 @@ impl Visitor<'_> for EarlyDocLinkResolver<'_, '_> {
self.parent_scope.module = old_module;
} else {
match &item.kind {
ItemKind::Impl(box ast::Impl { of_trait: Some(..), .. }) => {
ItemKind::Impl(box ast::Impl { of_trait: Some(trait_ref), .. }) => {
if let Some(partial_res) = self.resolver.get_partial_res(trait_ref.ref_id)
&& let Some(res) = partial_res.full_res()
&& let Some(trait_def_id) = res.opt_def_id()
&& !trait_def_id.is_local()
&& self.visited_mods.insert(trait_def_id) {
self.resolve_doc_links_extern_impl(trait_def_id, false);
}
self.all_trait_impls.push(self.resolver.local_def_id(item.id).to_def_id());
}
ItemKind::MacroDef(macro_def) if macro_def.macro_rules => {
Expand Down
14 changes: 14 additions & 0 deletions src/test/rustdoc/intra-doc/issue-104145.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Doc links in `Trait`'s methods are resolved because it has a local impl.

// aux-build:issue-103463-aux.rs

extern crate issue_103463_aux;
use issue_103463_aux::Trait;

pub struct LocalType;

impl Trait for LocalType {
fn method() {}
}

fn main() {}