Skip to content

Commit 046161f

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

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,20 @@ impl LinkCollector<'_, '_> {
12161216
.emit();
12171217
}
12181218

1219+
fn filter_private_hidden_candidates(&self, candidates: &mut Vec<(Res, Option<DefId>)>) {
1220+
candidates.retain(|(candidate, _)| {
1221+
let Res::Def(_, def_id) = candidate else { return true };
1222+
1223+
if !self.cx.render_options.document_private && !self.cx.tcx.visibility(def_id).is_public() {
1224+
false
1225+
} else if !self.cx.render_options.document_hidden && self.cx.tcx.is_doc_hidden(def_id) {
1226+
false
1227+
} else {
1228+
true
1229+
}
1230+
});
1231+
}
1232+
12191233
fn resolve_with_disambiguator_cached(
12201234
&mut self,
12211235
key: ResolutionInfo,
@@ -1250,6 +1264,8 @@ impl LinkCollector<'_, '_> {
12501264
}
12511265
}
12521266

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

0 commit comments

Comments
 (0)