Fixes #74134
After PR #72771 this would trigger an intra_doc_link_resolution_failure warning
when rustdoc is invoked without --document-private-items. Links from private
items to private types are however never actually generated in that case and
thus shouldn't produce a warning. These links are in fact a very useful tool to
document crate internals.
Tests are added for all 4 combinations of public/private items and link
targets. Test 1 is the case mentioned above and fails without this commit. Tests
2 - 4 passed before already but are added nonetheless to prevent regressions.
let hir_id = self.cx.tcx.hir().as_local_hir_id(local);
if !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_id)
+ && (item.visibility == Visibility::Public)
&& !self.cx.render_options.document_private
{
let item_name = item.name.as_deref().unwrap_or("<unknown>");
--- /dev/null
+#![deny(intra_doc_link_resolution_failure)]
+
+// Linking from a private item to a private type is fine without --document-private-items.
+
+struct Private;
+
+pub struct Public {
+ /// [`Private`]
+ private: Private,
+}
--- /dev/null
+// compile-flags: --document-private-items
+#![deny(intra_doc_link_resolution_failure)]
+
+// Linking from a private item to a private type is fine with --document-private-items.
+
+struct Private;
+
+pub struct Public {
+ /// [`Private`]
+ private: Private,
+}
--- /dev/null
+// should-fail
+#![deny(intra_doc_link_resolution_failure)]
+
+// Linking from a public item to a private type fails without --document-private-items.
+
+struct Private;
+
+pub struct Public {
+ /// [`Private`]
+ pub public: u32,
+}
--- /dev/null
+// compile-flags: --document-private-items
+#![deny(intra_doc_link_resolution_failure)]
+
+// Linking from a public item to a private type is fine with --document-private-items.
+
+struct Private;
+
+pub struct Public {
+ /// [`Private`]
+ pub public: u32,
+}