Skip to content

Commit 06721dd

Browse files
committed
Auto merge of #5543 - roblabla:doc-private-items, r=alexcrichton
Add document-private-items flag to cargo doc Add a `--document-private-items` flag to `cargo doc`, that mimics the equivalent `cargo rustdoc -- --document-private-items`. This works by relaying the flag to the underlying rustdoc call.
2 parents caf810b + 7757753 commit 06721dd

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/bin/cargo/commands/doc.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub fn cli() -> App {
1515
"Exclude packages from the build",
1616
)
1717
.arg(opt("no-deps", "Don't build documentation for dependencies"))
18+
.arg(opt("document-private-items", "Document private items"))
1819
.arg_jobs()
1920
.arg_targets_lib_bin(
2021
"Document only this package's library",
@@ -49,7 +50,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
4950
let mode = CompileMode::Doc {
5051
deps: !args.is_present("no-deps"),
5152
};
52-
let compile_opts = args.compile_options(config, mode)?;
53+
let mut compile_opts = args.compile_options(config, mode)?;
54+
compile_opts.target_rustdoc_args = if args.is_present("document-private-items") {
55+
Some(vec!["--document-private-items".to_string()])
56+
} else {
57+
None
58+
};
5359
let doc_opts = DocOptions {
5460
open_result: args.is_present("open"),
5561
compile_opts,

tests/testsuite/doc.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,3 +1649,22 @@ fn issue_5345() {
16491649
assert_that(foo.cargo("build"), execs().with_status(0));
16501650
assert_that(foo.cargo("doc"), execs().with_status(0));
16511651
}
1652+
1653+
#[test]
1654+
fn doc_private_items() {
1655+
let foo = project("foo")
1656+
.file(
1657+
"Cargo.toml",
1658+
r#"
1659+
[package]
1660+
name = "foo"
1661+
version = "0.0.1"
1662+
"#,
1663+
)
1664+
.file("src/lib.rs", "mod private { fn private_item() {} }")
1665+
.build();
1666+
assert_that(foo.cargo("doc").arg("--document-private-items"), execs().with_status(0));
1667+
1668+
assert_that(&foo.root().join("target/doc"), existing_dir());
1669+
assert_that(&foo.root().join("target/doc/foo/private/index.html"), existing_file());
1670+
}

0 commit comments

Comments
 (0)