Skip to content

Commit ca93310

Browse files
committed
rustdoc: Use rustdoc-reachable set to prune extern impls
1 parent 957bc60 commit ca93310

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/librustdoc/passes/collect_intra_doc_links/early.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
118118
}
119119
}
120120

121+
fn is_doc_reachable(&self, def_id: DefId) -> bool {
122+
self.extern_doc_reachable.contains(&def_id) || self.local_doc_reachable.contains(&def_id)
123+
}
124+
121125
/// Add traits in scope for links in impls collected by the `collect-intra-doc-links` pass.
122126
/// That pass filters impls using type-based information, but we don't yet have such
123127
/// information here, so we just conservatively calculate traits in scope for *all* modules
@@ -148,10 +152,10 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
148152
// privacy, private traits and impls from other crates are never documented in
149153
// the current crate, and links in their doc comments are not resolved.
150154
for &(trait_def_id, impl_def_id, simplified_self_ty) in &all_trait_impls {
151-
if self.resolver.cstore().visibility_untracked(trait_def_id).is_public()
152-
&& simplified_self_ty.and_then(|ty| ty.def()).map_or(true, |ty_def_id| {
153-
self.resolver.cstore().visibility_untracked(ty_def_id).is_public()
154-
})
155+
if self.is_doc_reachable(trait_def_id)
156+
&& simplified_self_ty
157+
.and_then(|ty| ty.def())
158+
.map_or(true, |ty_def_id| self.is_doc_reachable(ty_def_id))
155159
{
156160
if self.visited_mods.insert(trait_def_id) {
157161
self.resolve_doc_links_extern_impl(trait_def_id, false);
@@ -160,7 +164,7 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
160164
}
161165
}
162166
for (ty_def_id, impl_def_id) in all_inherent_impls {
163-
if self.resolver.cstore().visibility_untracked(ty_def_id).is_public() {
167+
if self.is_doc_reachable(ty_def_id) {
164168
self.resolve_doc_links_extern_impl(impl_def_id, true);
165169
}
166170
}

0 commit comments

Comments
 (0)