Skip to content

Commit dc869fc

Browse files
authored
Rollup merge of #104364 - petrochenkov:docice2, r=GuillaumeGomez
rustdoc: Resolve doc links in external traits having local impls For external impls it was done in #103192 right away, but the local impl case was forgotten. Fixes #104145.
2 parents 050ece6 + 8e81cc2 commit dc869fc

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

compiler/rustc_resolve/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,11 @@ impl<'a> Resolver<'a> {
19321932
}
19331933
}
19341934

1935+
/// For rustdoc.
1936+
pub fn get_partial_res(&self, node_id: NodeId) -> Option<PartialRes> {
1937+
self.partial_res_map.get(&node_id).copied()
1938+
}
1939+
19351940
/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
19361941
#[inline]
19371942
pub fn opt_span(&self, def_id: DefId) -> Option<Span> {

src/librustdoc/passes/collect_intra_doc_links/early.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,14 @@ impl Visitor<'_> for EarlyDocLinkResolver<'_, '_> {
354354
self.parent_scope.module = old_module;
355355
} else {
356356
match &item.kind {
357-
ItemKind::Impl(box ast::Impl { of_trait: Some(..), .. }) => {
357+
ItemKind::Impl(box ast::Impl { of_trait: Some(trait_ref), .. }) => {
358+
if let Some(partial_res) = self.resolver.get_partial_res(trait_ref.ref_id)
359+
&& let Some(res) = partial_res.full_res()
360+
&& let Some(trait_def_id) = res.opt_def_id()
361+
&& !trait_def_id.is_local()
362+
&& self.visited_mods.insert(trait_def_id) {
363+
self.resolve_doc_links_extern_impl(trait_def_id, false);
364+
}
358365
self.all_trait_impls.push(self.resolver.local_def_id(item.id).to_def_id());
359366
}
360367
ItemKind::MacroDef(macro_def) if macro_def.macro_rules => {
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Doc links in `Trait`'s methods are resolved because it has a local impl.
2+
3+
// aux-build:issue-103463-aux.rs
4+
5+
extern crate issue_103463_aux;
6+
use issue_103463_aux::Trait;
7+
8+
pub struct LocalType;
9+
10+
impl Trait for LocalType {
11+
fn method() {}
12+
}
13+
14+
fn main() {}

0 commit comments

Comments
 (0)