Skip to content

Commit 727baf0

Browse files
committed
When documenting private items in a binary, ignore warnings about links to private items
Previously, rustdoc would warn about linking to 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.
1 parent 01c06b0 commit 727baf0

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
@@ -646,6 +646,12 @@ pub fn create_bcx<'a, 'cfg>(
646646
if rustdoc_document_private_items || unit.target.is_bin() {
647647
let mut args = extra_args.take().unwrap_or_default();
648648
args.push("--document-private-items".into());
649+
if unit.target.is_bin() {
650+
// This warning only makes sense if it's possible to document private items
651+
// sometimes and ignore them at other times. But cargo consistently passes
652+
// `--document-private-items`, so the warning isn't useful.
653+
args.push("-Arustdoc::private-intra-doc-links".into());
654+
}
649655
extra_args = Some(args);
650656
}
651657

tests/testsuite/doc.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,3 +2767,24 @@ fn doc_check_cfg_features() {
27672767
)
27682768
.run();
27692769
}
2770+
2771+
#[cargo_test]
2772+
fn link_to_private_item() {
2773+
let main = r#"
2774+
//! [bar]
2775+
#[allow(dead_code)]
2776+
fn bar() {}
2777+
"#;
2778+
let p = project().file("src/lib.rs", main).build();
2779+
p.cargo("doc")
2780+
.with_stderr_contains("[..] documentation for `foo` links to private item `bar`")
2781+
.run();
2782+
// Check that binaries don't emit a private_intra_doc_links warning.
2783+
fs::rename(p.root().join("src/lib.rs"), p.root().join("src/main.rs")).unwrap();
2784+
p.cargo("doc")
2785+
.with_stderr(
2786+
"[DOCUMENTING] foo [..]\n\
2787+
[FINISHED] [..]",
2788+
)
2789+
.run();
2790+
}

0 commit comments

Comments
 (0)