Skip to content

Commit

Permalink
Auto merge of #11170 - basile-henry:basile-henry/built-in-alias-shado…
Browse files Browse the repository at this point in the history
…w, r=epage

Differentiate the warning when an alias (built-in or user-defined) shadows an external subcommand

Fixes #11149
  • Loading branch information
bors committed Oct 13, 2022
2 parents 3513780 + 3ff6d9e commit b332991
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,19 +262,21 @@ To pass the arguments to the subcommand, remove `--`",
}
(None, Ok(None)) => {}
(None, Ok(Some(alias))) => {
// Check if this alias is shadowing an external subcommand
// Check if a user-defined alias is shadowing an external subcommand
// (binary of the form `cargo-<subcommand>`)
// Currently this is only a warning, but after a transition period this will become
// a hard error.
if let Some(path) = super::find_external_subcommand(config, cmd) {
config.shell().warn(format!(
if super::builtin_aliases_execs(cmd).is_none() {
if let Some(path) = super::find_external_subcommand(config, cmd) {
config.shell().warn(format!(
"\
user-defined alias `{}` is shadowing an external subcommand found at: `{}`
This was previously accepted but is being phased out; it will become a hard error in a future release.
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.",
cmd,
path.display(),
))?;
}
}

let mut alias = alias
Expand Down
24 changes: 24 additions & 0 deletions tests/testsuite/cargo_alias_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,30 @@ fn dependent_alias() {
.run();
}

#[cargo_test]
fn builtin_alias_shadowing_external_subcommand() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/main.rs", "fn main() {}")
.executable("cargo-t", "")
.build();

let mut paths: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect();
paths.push(p.root());
let path = env::join_paths(paths).unwrap();

p.cargo("t")
.env("PATH", &path)
.with_stderr(
"\
[COMPILING] foo v0.5.0 [..]
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
[RUNNING] unittests src/main.rs [..]
",
)
.run();
}

#[cargo_test]
fn alias_shadowing_external_subcommand() {
let echo = echo_subcommand();
Expand Down

0 comments on commit b332991

Please sign in to comment.