1
Fork 0

rustdoc: Allow linking from private items to private types

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.
This commit is contained in:
Dennis Hamester 2020-07-08 07:39:49 +02:00
parent 8ac1525e09
commit c8b16cdbd0
5 changed files with 44 additions and 0 deletions

View file

@ -796,6 +796,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
let hir_id = self.cx.tcx.hir().as_local_hir_id(local); 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) if !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_id)
&& (item.visibility == Visibility::Public)
&& !self.cx.render_options.document_private && !self.cx.render_options.document_private
{ {
let item_name = item.name.as_deref().unwrap_or("<unknown>"); let item_name = item.name.as_deref().unwrap_or("<unknown>");

View file

@ -0,0 +1,10 @@
#![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,
}

View file

@ -0,0 +1,11 @@
// 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,
}

View file

@ -0,0 +1,11 @@
// 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,
}

View file

@ -0,0 +1,11 @@
// 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,
}