Skip to content

Commit e7ee237

Browse files
Add --document-private-items for binary crates by default
1 parent d0a41be commit e7ee237

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

src/bin/cargo/commands/doc.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
5555
};
5656
let mut compile_opts =
5757
args.compile_options(config, mode, Some(&ws), ProfileChecking::Checked)?;
58-
compile_opts.local_rustdoc_args = if args.is_present("document-private-items") {
59-
Some(vec!["--document-private-items".to_string()])
60-
} else {
61-
None
62-
};
58+
compile_opts.rustdoc_document_private_items = args.is_present("document-private-items");
59+
6360
let doc_opts = DocOptions {
6461
open_result: args.is_present("open"),
6562
compile_opts,

src/cargo/ops/cargo_compile.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ pub struct CompileOptions<'a> {
6666
pub target_rustc_args: Option<Vec<String>>,
6767
/// Extra arguments passed to all selected targets for rustdoc.
6868
pub local_rustdoc_args: Option<Vec<String>>,
69+
/// Whether the `--document-private-items` flags was specified and should
70+
/// be forwarded to `rustdoc`.
71+
pub rustdoc_document_private_items: bool,
6972
/// The directory to copy final artifacts to. Note that even if `out_dir` is
7073
/// set, a copy of artifacts still could be found a `target/(debug\release)`
7174
/// as usual.
@@ -89,6 +92,7 @@ impl<'a> CompileOptions<'a> {
8992
target_rustdoc_args: None,
9093
target_rustc_args: None,
9194
local_rustdoc_args: None,
95+
rustdoc_document_private_items: false,
9296
export_dir: None,
9397
})
9498
}
@@ -271,6 +275,7 @@ pub fn compile_ws<'a>(
271275
ref target_rustdoc_args,
272276
ref target_rustc_args,
273277
ref local_rustdoc_args,
278+
rustdoc_document_private_items,
274279
ref export_dir,
275280
} = *options;
276281

@@ -434,9 +439,20 @@ pub fn compile_ws<'a>(
434439
}
435440
bcx.extra_compiler_args.insert(units[0], args);
436441
}
437-
if let Some(args) = local_rustdoc_args {
438-
for unit in &units {
439-
if unit.mode.is_doc() || unit.mode.is_doc_test() {
442+
for unit in &units {
443+
if unit.mode.is_doc() || unit.mode.is_doc_test() {
444+
let mut extra_args = local_rustdoc_args.clone();
445+
446+
// Add `--document-private-items` rustdoc flag if requested or if
447+
// the target is a binary. Binary crates get their private items
448+
// documented by default.
449+
if rustdoc_document_private_items || unit.target.is_bin() {
450+
let mut args = extra_args.take().unwrap_or(vec![]);
451+
args.push("--document-private-items".into());
452+
extra_args = Some(args);
453+
}
454+
455+
if let Some(args) = extra_args {
440456
bcx.extra_compiler_args.insert(*unit, args.clone());
441457
}
442458
}

src/cargo/ops/cargo_package.rs

+1
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ fn run_verify(ws: &Workspace<'_>, tar: &FileLock, opts: &PackageOpts<'_>) -> Car
661661
target_rustdoc_args: None,
662662
target_rustc_args: rustc_args,
663663
local_rustdoc_args: None,
664+
rustdoc_document_private_items: false,
664665
export_dir: None,
665666
},
666667
&exec,

src/cargo/util/command_prelude.rs

+1
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ pub trait ArgMatchesExt {
463463
target_rustdoc_args: None,
464464
target_rustc_args: None,
465465
local_rustdoc_args: None,
466+
rustdoc_document_private_items: false,
466467
export_dir: None,
467468
};
468469

0 commit comments

Comments
 (0)