diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index 57cb31c38d4..7b7725fa271 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -492,7 +492,7 @@ pub fn cli() -> Command { let usage = if is_rustup { "cargo [+toolchain] [OPTIONS] [COMMAND]\n cargo [+toolchain] [OPTIONS] -Zscript [ARGS]..." } else { - "cargo [OPTIONS] [COMMAND]\n cargo [OPTIONS] -Zscript [ARGS]..." + "cargo [OPTIONS] [COMMAND]\n cargo [OPTIONS] -Zscript [ARGS]..." }; Command::new("cargo") // Subcommands all count their args' display order independently (from 0), diff --git a/src/bin/cargo/commands/run.rs b/src/bin/cargo/commands/run.rs index 8ee7d3f9aa9..9db28bc626c 100644 --- a/src/bin/cargo/commands/run.rs +++ b/src/bin/cargo/commands/run.rs @@ -87,7 +87,9 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { pub fn is_manifest_command(arg: &str) -> bool { let path = Path::new(arg); - 1 < path.components().count() || path.extension() == Some(OsStr::new("rs")) + 1 < path.components().count() + || path.extension() == Some(OsStr::new("rs")) + || path.file_name() == Some(OsStr::new("Cargo.toml")) } pub fn exec_manifest_command(config: &Config, cmd: &str, args: &[OsString]) -> CliResult { diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index afb2f7cbd61..d33980ff51e 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -1462,16 +1462,19 @@ persistent lockfile. #### Manifest-commands -You may pass single-file packages directly to the `cargo` command, without subcommand. This is mostly intended for being put in `#!` lines. +You may pass a manifest directly to the `cargo` command, without a subcommand, +like `foo/Cargo.toml` or a single-file package like `foo.rs`. This is mostly +intended for being put in `#!` lines. The precedence for how to interpret `cargo ` is 1. Built-in xor single-file packages 2. Aliases 3. External subcommands -A parameter is identified as a single-file package if it has one of: +A parameter is identified as a manifest-command if it has one of: - Path separators - A `.rs` extension +- The file name is `Cargo.toml` ### `[lints]` diff --git a/tests/testsuite/script.rs b/tests/testsuite/script.rs index 638677bc4b3..bf4fc75f27b 100644 --- a/tests/testsuite/script.rs +++ b/tests/testsuite/script.rs @@ -65,6 +65,29 @@ args: [] .run(); } +#[cargo_test] +fn basic_cargo_toml() { + let p = cargo_test_support::project() + .file("src/main.rs", ECHO_SCRIPT) + .build(); + + p.cargo("-Zscript Cargo.toml") + .masquerade_as_nightly_cargo(&["script"]) + .with_stdout( + r#"bin: target/debug/foo[EXE] +args: [] +"#, + ) + .with_stderr( + "\ +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s +[RUNNING] `target/debug/foo[EXE]` +", + ) + .run(); +} + #[cargo_test] fn path_required() { let p = cargo_test_support::project()