From e5d10f973d68856c4d602c3523234623d1cb211c Mon Sep 17 00:00:00 2001 From: Alik Aslanyan Date: Wed, 9 Jun 2021 18:41:46 +0400 Subject: [PATCH] Implement warning for ignored trailing arguments in case built-in `cargo` command was invoked with `--` --- src/bin/cargo/cli.rs | 13 ++++++++++++- tests/testsuite/cargo_alias_config.rs | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index b891836cb90..e3a62cd161a 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -1,6 +1,7 @@ use cargo::core::{features, CliUnstable}; use cargo::{self, drop_print, drop_println, CliResult, Config}; use clap::{AppSettings, Arg, ArgMatches}; +use itertools::Itertools; use super::commands; use super::list_commands; @@ -169,6 +170,17 @@ fn expand_aliases( cmd, ))?; } + (Some(_), None) => { + // Command is built-in and is not conflicting with alias, but contains ignored values. + if let Some(mut values) = args.values_of("") { + config.shell().warn(format!( + "trailing arguments after built-in command `{}` are ignored: `{}`", + cmd, + values.join(" "), + ))?; + } + } + (None, None) => {} (_, Some(mut alias)) => { alias.extend( args.values_of("") @@ -186,7 +198,6 @@ fn expand_aliases( let (expanded_args, _) = expand_aliases(config, new_args)?; return Ok((expanded_args, global_args)); } - (_, None) => {} } }; diff --git a/tests/testsuite/cargo_alias_config.rs b/tests/testsuite/cargo_alias_config.rs index 2e2c7e33866..ba271624725 100644 --- a/tests/testsuite/cargo_alias_config.rs +++ b/tests/testsuite/cargo_alias_config.rs @@ -192,3 +192,21 @@ fn global_options_with_alias() { ) .run(); } + +#[cargo_test] +fn weird_check() { + let p = project() + .file("Cargo.toml", &basic_bin_manifest("foo")) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("-- check --invalid_argument -some-other-argument") + .with_stderr( + "\ +[WARNING] trailing arguments after built-in command `check` are ignored: `--invalid_argument -some-other-argument` +[CHECKING] foo v0.5.0 ([..]) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +}