Skip to content

Commit 5ed0792

Browse files
committed
fix(embedded): Ensure we don't auto-discover any targets
1 parent 575b9ac commit 5ed0792

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/cargo/util/toml/embedded.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const DEFAULT_EDITION: crate::core::features::Edition =
88
crate::core::features::Edition::LATEST_STABLE;
99
const DEFAULT_VERSION: &str = "0.0.0";
1010
const DEFAULT_PUBLISH: bool = false;
11+
const AUTO_FIELDS: &[&str] = &["autobins", "autoexamples", "autotests", "autobenches"];
1112

1213
pub fn expand_manifest(
1314
content: &str,
@@ -57,8 +58,11 @@ fn expand_manifest_(
5758
.or_insert_with(|| toml::Table::new().into())
5859
.as_table_mut()
5960
.ok_or_else(|| anyhow::format_err!("`package` must be a table"))?;
60-
for key in ["workspace", "build", "links"] {
61-
if package.contains_key(key) {
61+
for key in ["workspace", "build", "links"]
62+
.iter()
63+
.chain(AUTO_FIELDS.iter())
64+
{
65+
if package.contains_key(*key) {
6266
anyhow::bail!("`package.{key}` is not allowed in embedded manifests")
6367
}
6468
}
@@ -88,6 +92,11 @@ fn expand_manifest_(
8892
package
8993
.entry("publish".to_owned())
9094
.or_insert_with(|| toml::Value::Boolean(DEFAULT_PUBLISH));
95+
for field in AUTO_FIELDS {
96+
package
97+
.entry(field.to_owned())
98+
.or_insert_with(|| toml::Value::Boolean(false));
99+
}
91100

92101
let mut bin = toml::Table::new();
93102
bin.insert("name".to_owned(), toml::Value::String(bin_name));
@@ -363,6 +372,10 @@ name = "test-"
363372
path = "test.rs"
364373
365374
[package]
375+
autobenches = false
376+
autobins = false
377+
autoexamples = false
378+
autotests = false
366379
edition = "2021"
367380
name = "test-"
368381
publish = false
@@ -388,6 +401,10 @@ path = "test.rs"
388401
time = "0.1.25"
389402
390403
[package]
404+
autobenches = false
405+
autobins = false
406+
autoexamples = false
407+
autotests = false
391408
edition = "2021"
392409
name = "test-"
393410
publish = false

tests/testsuite/script.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,16 @@ fn main() {
523523

524524
p.cargo("-Zscript script.rs --help")
525525
.masquerade_as_nightly_cargo(&["script"])
526-
.with_status(101)
526+
.with_stdout(
527+
r#"Hello world!
528+
"#,
529+
)
527530
.with_stderr(
528531
"\
529532
[WARNING] `package.edition` is unspecifiead, defaulting to `2021`
530-
[ERROR] `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key.
531-
available binaries: not-script, script
533+
[COMPILING] script v0.0.0 ([ROOT]/foo)
534+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
535+
[RUNNING] `[..]/debug/script[EXE] --help`
532536
",
533537
)
534538
.run();

0 commit comments

Comments
 (0)