Skip to content

Commit 08b8fe5

Browse files
committed
Auto merge of #10142 - jyn514:bin-private-link, r=ehuss
When documenting private items in a binary, ignore warnings about links to private items Previously, rustdoc would warn about linking to private items in a binary, even though cargo unconditionally documents private items in a binary. This changes cargo to silence the warning, since it's only relevant in cases where the private items might not be documented. Fixes rust-lang/rust#89600.
2 parents 0f75da6 + 727baf0 commit 08b8fe5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/cargo/ops/cargo_compile.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,12 @@ pub fn create_bcx<'a, 'cfg>(
623623
if rustdoc_document_private_items || unit.target.is_bin() {
624624
let mut args = extra_args.take().unwrap_or_default();
625625
args.push("--document-private-items".into());
626+
if unit.target.is_bin() {
627+
// This warning only makes sense if it's possible to document private items
628+
// sometimes and ignore them at other times. But cargo consistently passes
629+
// `--document-private-items`, so the warning isn't useful.
630+
args.push("-Arustdoc::private-intra-doc-links".into());
631+
}
626632
extra_args = Some(args);
627633
}
628634

tests/testsuite/doc.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,3 +2819,24 @@ fn doc_check_cfg_features() {
28192819
)
28202820
.run();
28212821
}
2822+
2823+
#[cargo_test]
2824+
fn link_to_private_item() {
2825+
let main = r#"
2826+
//! [bar]
2827+
#[allow(dead_code)]
2828+
fn bar() {}
2829+
"#;
2830+
let p = project().file("src/lib.rs", main).build();
2831+
p.cargo("doc")
2832+
.with_stderr_contains("[..] documentation for `foo` links to private item `bar`")
2833+
.run();
2834+
// Check that binaries don't emit a private_intra_doc_links warning.
2835+
fs::rename(p.root().join("src/lib.rs"), p.root().join("src/main.rs")).unwrap();
2836+
p.cargo("doc")
2837+
.with_stderr(
2838+
"[DOCUMENTING] foo [..]\n\
2839+
[FINISHED] [..]",
2840+
)
2841+
.run();
2842+
}

0 commit comments

Comments
 (0)