forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#74147 - dennis-hamester:fix/issue-74134, r=…
…jyn514 rustdoc: Allow linking from private items to private types Fixes rust-lang#74134 After PR rust-lang#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.
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |