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.
This commit is contained in:
Joshua Nelson 2021-11-30 14:25:55 -05:00 committed by Joshua Nelson
parent 01c06b0360
commit 727baf0db1
2 changed files with 27 additions and 0 deletions

View File

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

View File

@ -2767,3 +2767,24 @@ fn doc_check_cfg_features() {
)
.run();
}
#[cargo_test]
fn link_to_private_item() {
let main = r#"
//! [bar]
#[allow(dead_code)]
fn bar() {}
"#;
let p = project().file("src/lib.rs", main).build();
p.cargo("doc")
.with_stderr_contains("[..] documentation for `foo` links to private item `bar`")
.run();
// Check that binaries don't emit a private_intra_doc_links warning.
fs::rename(p.root().join("src/lib.rs"), p.root().join("src/main.rs")).unwrap();
p.cargo("doc")
.with_stderr(
"[DOCUMENTING] foo [..]\n\
[FINISHED] [..]",
)
.run();
}