Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,18 @@ fn expand_aliases(
}
(None, None) => {}
(_, Some(mut alias)) => {
// Check if this 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!(
"user-defined alias `{}` is shadowing an external subcommand found at: `{}`",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this include additional text explaining that this will become an error in the future? And some detail explaining why it is being changed (perhaps just a link to #10049 will be sufficient). Maybe something like this?

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(),
))?;
}

alias.extend(
args.values_of("")
.unwrap_or_default()
Expand Down
10 changes: 7 additions & 3 deletions src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,16 @@ fn list_commands(config: &Config) -> BTreeMap<String, CommandInfo> {
commands
}

fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> CliResult {
fn find_external_subcommand(config: &Config, cmd: &str) -> Option<PathBuf> {
let command_exe = format!("cargo-{}{}", cmd, env::consts::EXE_SUFFIX);
let path = search_directories(config)
search_directories(config)
.iter()
.map(|dir| dir.join(&command_exe))
.find(|file| is_executable(file));
.find(|file| is_executable(file))
}

fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> CliResult {
let path = find_external_subcommand(config, cmd);
let command = match path {
Some(command) => command,
None => {
Expand Down
12 changes: 9 additions & 3 deletions tests/testsuite/cargo_alias_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,20 @@ fn default_args_alias() {
p.cargo("echo")
.env("PATH", &path)
.with_status(101)
.with_stderr("error: alias echo has unresolvable recursive definition: echo -> echo")
.with_stderr("\
warning: user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo`
error: alias echo has unresolvable recursive definition: echo -> echo
",
)
.run();

p.cargo("test-1")
.env("PATH", &path)
.with_status(101)
.with_stderr(
"error: alias test-1 has unresolvable recursive definition: test-1 -> echo -> echo",
.with_stderr("\
warning: user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo`
error: alias test-1 has unresolvable recursive definition: test-1 -> echo -> echo
",
)
.run();

Expand Down