diff --git a/src/cargo/util/toml/embedded.rs b/src/cargo/util/toml/embedded.rs index 33096f48af82..f1bd15ef2320 100644 --- a/src/cargo/util/toml/embedded.rs +++ b/src/cargo/util/toml/embedded.rs @@ -7,6 +7,7 @@ const DEFAULT_EDITION: crate::core::features::Edition = crate::core::features::Edition::LATEST_STABLE; const DEFAULT_VERSION: &str = "0.0.0"; const DEFAULT_PUBLISH: bool = false; +const AUTO_FIELDS: &[&str] = &["autobins", "autoexamples", "autotests", "autobenches"]; pub fn expand_manifest( content: &str, @@ -56,8 +57,11 @@ fn expand_manifest_( .or_insert_with(|| toml::Table::new().into()) .as_table_mut() .ok_or_else(|| anyhow::format_err!("`package` must be a table"))?; - for key in ["workspace", "build", "links"] { - if package.contains_key(key) { + for key in ["workspace", "build", "links"] + .iter() + .chain(AUTO_FIELDS.iter()) + { + if package.contains_key(*key) { anyhow::bail!("`package.{key}` is not allowed in embedded manifests") } } @@ -84,6 +88,11 @@ fn expand_manifest_( package .entry("publish".to_owned()) .or_insert_with(|| toml::Value::Boolean(DEFAULT_PUBLISH)); + for field in AUTO_FIELDS { + package + .entry(field.to_owned()) + .or_insert_with(|| toml::Value::Boolean(false)); + } let mut bin = toml::Table::new(); bin.insert("name".to_owned(), toml::Value::String(bin_name)); @@ -355,6 +364,10 @@ name = "test" path = "/home/me/test.rs" [package] +autobenches = false +autobins = false +autoexamples = false +autotests = false edition = "2021" name = "test" publish = false @@ -380,6 +393,10 @@ path = "/home/me/test.rs" time = "0.1.25" [package] +autobenches = false +autobins = false +autoexamples = false +autotests = false edition = "2021" name = "test" publish = false diff --git a/tests/testsuite/script.rs b/tests/testsuite/script.rs index b02d1efe5b0d..0aba7652cbbb 100644 --- a/tests/testsuite/script.rs +++ b/tests/testsuite/script.rs @@ -523,12 +523,16 @@ fn main() { p.cargo("-Zscript script.rs --help") .masquerade_as_nightly_cargo(&["script"]) - .with_status(101) + .with_stdout( + r#"Hello world! +"#, + ) .with_stderr( "\ [WARNING] `package.edition` is unspecifiead, defaulting to `2021` -[ERROR] `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key. -available binaries: not-script, script +[COMPILING] script v0.0.0 ([ROOT]/foo) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s +[RUNNING] `target/debug/script[EXE] --help` ", ) .run();