Skip to content

Commit 8230b46

Browse files
committed
Auto merge of #12637 - ehuss:clean-doc-p, r=weihanglo
Error out if `cargo clean --doc` is mixed with `-p`. This changes `cargo clean --doc -p foo` to generate an error instead of ignoring the `-p` flag. There is still an outstanding issue #8790 tracking this. It *should* support `-p`, but until it is supported, I think cargo should tell you that the flag is ignored. This is also in preparation for some code changes in #12634 which needs to handle any combination of various different clean flags.
2 parents baca00e + f49b038 commit 8230b46

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/cargo/ops/cargo_clean.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::util::errors::CargoResult;
77
use crate::util::interning::InternedString;
88
use crate::util::{Config, Progress, ProgressStyle};
99

10-
use anyhow::Context as _;
10+
use anyhow::{bail, Context as _};
1111
use cargo_util::paths;
1212
use std::fs;
1313
use std::path::Path;
@@ -33,6 +33,15 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
3333

3434
// If the doc option is set, we just want to delete the doc directory.
3535
if opts.doc {
36+
if !opts.spec.is_empty() {
37+
// FIXME: https://github.com/rust-lang/cargo/issues/8790
38+
// This should support the ability to clean specific packages
39+
// within the doc directory. It's a little tricky since it
40+
// needs to find all documentable targets, but also consider
41+
// the fact that target names might overlap with dependency
42+
// names and such.
43+
bail!("--doc cannot be used with -p");
44+
}
3645
target_dir = target_dir.join("doc");
3746
return clean_entire_folder(&target_dir.into_path_unlocked(), config);
3847
}

tests/testsuite/clean.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,3 +673,13 @@ fn clean_spec_reserved() {
673673
)
674674
.run();
675675
}
676+
677+
#[cargo_test]
678+
fn doc_with_package_selection() {
679+
// --doc with -p
680+
let p = project().file("src/lib.rs", "").build();
681+
p.cargo("clean --doc -p foo")
682+
.with_status(101)
683+
.with_stderr("error: --doc cannot be used with -p")
684+
.run();
685+
}

0 commit comments

Comments
 (0)