Skip to content

Commit 6c20cd3

Browse files
Remove intra doc link items if they are private/hidden and the matching option is not enabled
1 parent 59d4114 commit 6c20cd3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,25 @@ impl LinkCollector<'_, '_> {
12161216
.emit();
12171217
}
12181218

1219+
fn filter_private_hidden_candidates(&self, candidates: &mut Vec<(Res, Option<DefId>)>, module_def_id: DefId) {
1220+
candidates.retain(|(candidate, _)| {
1221+
let Res::Def(_, def_id) = candidate else { return true };
1222+
1223+
if !self.cx.render_options.document_private
1224+
&& let visibility = self.cx.tcx.visibility(def_id)
1225+
&& !visibility.is_public()
1226+
&& !self.cx.tcx.has_attr(*def_id, sym::rustc_doc_primitive)
1227+
&& !visibility.is_accessible_from(module_def_id, self.cx.tcx)
1228+
{
1229+
false
1230+
} else if !self.cx.render_options.document_hidden && self.cx.tcx.is_doc_hidden(def_id) {
1231+
false
1232+
} else {
1233+
true
1234+
}
1235+
});
1236+
}
1237+
12191238
fn resolve_with_disambiguator_cached(
12201239
&mut self,
12211240
key: ResolutionInfo,
@@ -1250,6 +1269,8 @@ impl LinkCollector<'_, '_> {
12501269
}
12511270
}
12521271

1272+
self.filter_private_hidden_candidates(&mut candidates, key.module_id);
1273+
12531274
// If there are multiple items with the same "kind" (for example, both "associated types")
12541275
// and after removing duplicated kinds, only one remains, the `ambiguity_error` function
12551276
// won't emit an error. So at this point, we can just take the first candidate as it was

0 commit comments

Comments
 (0)