diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-11-13 16:31:00 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-11-13 17:20:24 +0300 |
| commit | 8e81cc262e08e4c93df3ac9c1a3814372e4908c8 (patch) | |
| tree | 9878897b95b4fe729bb38e7702092334659ad6cd | |
| parent | 928d14bcd1976ffd33e743aa09c7c22a063bf87c (diff) | |
rustdoc: Resolve doc links in external traits having local impls
| -rw-r--r-- | compiler/rustc_resolve/src/lib.rs | 5 | ||||
| -rw-r--r-- | src/librustdoc/passes/collect_intra_doc_links/early.rs | 9 | ||||
| -rw-r--r-- | src/test/rustdoc/intra-doc/issue-104145.rs | 14 |
3 files changed, 27 insertions, 1 deletions
diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index a1ff477c6fe..9ca3588fff4 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -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> { diff --git a/src/librustdoc/passes/collect_intra_doc_links/early.rs b/src/librustdoc/passes/collect_intra_doc_links/early.rs index d121a3e2aa4..1b373cfe5bb 100644 --- a/src/librustdoc/passes/collect_intra_doc_links/early.rs +++ b/src/librustdoc/passes/collect_intra_doc_links/early.rs @@ -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 => { diff --git a/src/test/rustdoc/intra-doc/issue-104145.rs b/src/test/rustdoc/intra-doc/issue-104145.rs new file mode 100644 index 00000000000..9ce36740d60 --- /dev/null +++ b/src/test/rustdoc/intra-doc/issue-104145.rs @@ -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() {} |
