Skip to content

Commit

Permalink
Auto merge of #10142 - jyn514:bin-private-link, r=ehuss
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed May 6, 2022
2 parents 0f75da6 + 727baf0 commit 08b8fe5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,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);
}

Expand Down
21 changes: 21 additions & 0 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2819,3 +2819,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();
}

0 comments on commit 08b8fe5

Please sign in to comment.