From bb951880934c8f2eff77ce28673debff00ae7b6e Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 3 Jul 2020 22:09:31 -0400 Subject: [PATCH 1/3] Don't overwrite existing `rustdoc` args with --document-private-items Instead, add that flag in addition to any existing flags. --- src/cargo/ops/cargo_compile.rs | 9 +++++++-- tests/testsuite/rustdoc.rs | 13 +++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 3bb256f9fa1..179bf00b902 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -475,8 +475,13 @@ pub fn create_bcx<'a, 'cfg>( extra_args = Some(args); } - if let Some(args) = extra_args { - extra_compiler_args.insert(unit.clone(), args.clone()); + if let Some(mut args) = extra_args { + match extra_compiler_args.get_mut(&unit) { + None => { + extra_compiler_args.insert(unit.clone(), args); + } + Some(existing) => existing.append(&mut args), + } } } } diff --git a/tests/testsuite/rustdoc.rs b/tests/testsuite/rustdoc.rs index 26f9a68513b..93b2bfd7289 100644 --- a/tests/testsuite/rustdoc.rs +++ b/tests/testsuite/rustdoc.rs @@ -39,6 +39,19 @@ fn rustdoc_args() { .run(); } +#[cargo_test] +fn rustdoc_binary_args_passed() { + let p = project().file("src/main.rs", "").build(); + + p.cargo("rustdoc -v") + .arg("--") + .arg("--theme") + .arg("dark") + .with_stderr_contains("[RUNNING] `rustdoc [..] --theme dark[..]`") + .with_status(101) + .run(); +} + #[cargo_test] fn rustdoc_foo_with_bar_dependency() { let foo = project() From 0a975e96d86810aa3986858febede53a90c369c0 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sat, 4 Jul 2020 15:04:44 -0400 Subject: [PATCH 2/3] Use a stable rustdoc option for testing --- tests/testsuite/rustdoc.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/testsuite/rustdoc.rs b/tests/testsuite/rustdoc.rs index 93b2bfd7289..860428a9223 100644 --- a/tests/testsuite/rustdoc.rs +++ b/tests/testsuite/rustdoc.rs @@ -45,10 +45,8 @@ fn rustdoc_binary_args_passed() { p.cargo("rustdoc -v") .arg("--") - .arg("--theme") - .arg("dark") - .with_stderr_contains("[RUNNING] `rustdoc [..] --theme dark[..]`") - .with_status(101) + .arg("--markdown-no-toc") + .with_stderr_contains("[RUNNING] `rustdoc [..] --markdown-no-toc[..]`") .run(); } From 1d1b3447813e4f39a6183a456de22ed3abe5ae87 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sat, 4 Jul 2020 15:47:26 -0400 Subject: [PATCH 3/3] Use entry API instead of a match This makes the code easier to read and also avoids looking up the position in the map twice. The clone of `unit` is very cheap since it is an Rc. --- src/cargo/ops/cargo_compile.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 179bf00b902..5e9a764346f 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -475,13 +475,11 @@ pub fn create_bcx<'a, 'cfg>( extra_args = Some(args); } - if let Some(mut args) = extra_args { - match extra_compiler_args.get_mut(&unit) { - None => { - extra_compiler_args.insert(unit.clone(), args); - } - Some(existing) => existing.append(&mut args), - } + if let Some(args) = extra_args { + extra_compiler_args + .entry(unit.clone()) + .or_default() + .extend(args); } } }