Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {

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>");
Expand Down
10 changes: 10 additions & 0 deletions src/test/rustdoc-ui/issue-74134.public.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
warning: `[PrivateType]` public documentation for `public_item` links to a private item
--> $DIR/issue-74134.rs:19:10
|
LL | /// [`PrivateType`]
| ^^^^^^^^^^^^^ this item is private
|
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default

warning: 1 warning emitted

41 changes: 41 additions & 0 deletions src/test/rustdoc-ui/issue-74134.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// revisions: public private
// [private]compile-flags: --document-private-items
// check-pass

// There are 4 cases here:
// 1. public item -> public type: no warning
// 2. public item -> private type: warning, if --document-private-items is not passed
// 3. private item -> public type: no warning
// 4. private item -> private type: no warning
// All 4 cases are tested with and without --document-private-items.
//
// Case 4 without --document-private-items is the one described in issue #74134.

struct PrivateType;
pub struct PublicType;

pub struct Public {
/// [`PublicType`]
/// [`PrivateType`]
//[public]~^ WARNING public documentation for `public_item` links to a private
pub public_item: u32,

/// [`PublicType`]
/// [`PrivateType`]
private_item: u32,
}

// The following cases are identical to the ones above, except that they are in a private
// module. Thus they all fall into cases 3 and 4 and should not produce a warning.

mod private {
pub struct Public {
/// [`super::PublicType`]
/// [`super::PrivateType`]
pub public_item: u32,

/// [`super::PublicType`]
/// [`super::PrivateType`]
private_item: u32,
}
}