Skip to content

Commit 1d34c32

Browse files
Remove intra doc link items if they are private/hidden and the matching option is not enabled
1 parent 9e3e517 commit 1d34c32

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,24 @@ impl LinkCollector<'_, '_> {
12271227
.emit();
12281228
}
12291229

1230+
fn filter_private_hidden_candidates(&self, candidates: &mut Vec<(Res, Option<DefId>)>) {
1231+
candidates.retain(|(candidate, _)| {
1232+
let Res::Def(_, def_id) = candidate else { return true };
1233+
1234+
if !self.cx.render_options.document_private
1235+
&& let visibility = self.cx.tcx.visibility(def_id)
1236+
&& !visibility.is_public()
1237+
&& !self.cx.tcx.has_attr(*def_id, sym::rustc_doc_primitive)
1238+
{
1239+
false
1240+
} else if !self.cx.render_options.document_hidden && self.cx.tcx.is_doc_hidden(def_id) {
1241+
false
1242+
} else {
1243+
true
1244+
}
1245+
});
1246+
}
1247+
12301248
fn resolve_with_disambiguator_cached(
12311249
&mut self,
12321250
key: ResolutionInfo,
@@ -1261,6 +1279,8 @@ impl LinkCollector<'_, '_> {
12611279
}
12621280
}
12631281

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

0 commit comments

Comments
 (0)