Skip to content

Commit 8713cd7

Browse files
committed
Give a hard error if -Zrustdoc-scrape-examples is missing a flag
It's the same as if the flag wasn't passed, and it makes it difficult to figure out why rustdoc isn't generating examples.
1 parent b4ab730 commit 8713cd7

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/cargo/core/features.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,15 @@ impl CliUnstable {
874874
"namespaced-features" => self.namespaced_features = parse_empty(k, v)?,
875875
"weak-dep-features" => self.weak_dep_features = parse_empty(k, v)?,
876876
"credential-process" => self.credential_process = parse_empty(k, v)?,
877-
"rustdoc-scrape-examples" => self.rustdoc_scrape_examples = v.map(|s| s.to_string()),
877+
"rustdoc-scrape-examples" => {
878+
if let Some(s) = v {
879+
self.rustdoc_scrape_examples = Some(s.to_string())
880+
} else {
881+
bail!(
882+
r#"-Z rustdoc-scrape-examples must take "all" or "examples" as an argument"#
883+
)
884+
}
885+
}
878886
"skip-rustdoc-fingerprint" => self.skip_rustdoc_fingerprint = parse_empty(k, v)?,
879887
"compile-progress" => stabilized_warn(k, "1.30", STABILIZED_COMPILE_PROGRESS),
880888
"offline" => stabilized_err(k, "1.36", STABILIZED_OFFLINE)?,

tests/testsuite/doc.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,3 +2326,28 @@ fn scrape_examples_crate_with_dash() {
23262326
let doc_html = p.read_file("target/doc/da_sh/fn.foo.html");
23272327
assert!(doc_html.contains("Examples found in repository"));
23282328
}
2329+
2330+
#[cargo_test]
2331+
fn scrape_examples_missing_flag() {
2332+
if !is_nightly() {
2333+
return;
2334+
}
2335+
2336+
let p = project()
2337+
.file(
2338+
"Cargo.toml",
2339+
r#"
2340+
[package]
2341+
name = "foo"
2342+
version = "1.2.4"
2343+
authors = []
2344+
"#,
2345+
)
2346+
.file("src/lib.rs", "//! These are the docs!")
2347+
.build();
2348+
p.cargo("doc -Zrustdoc-scrape-examples")
2349+
.masquerade_as_nightly_cargo()
2350+
.with_status(101)
2351+
.with_stderr("error: -Z rustdoc-scrape-examples must take [..] an argument")
2352+
.run();
2353+
}

0 commit comments

Comments
 (0)