Skip to content

Commit b332991

Browse files
committed
Auto merge of #11170 - basile-henry:basile-henry/built-in-alias-shadow, r=epage
Differentiate the warning when an alias (built-in or user-defined) shadows an external subcommand Fixes #11149
2 parents 3513780 + 3ff6d9e commit b332991

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/bin/cargo/cli.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,19 +262,21 @@ To pass the arguments to the subcommand, remove `--`",
262262
}
263263
(None, Ok(None)) => {}
264264
(None, Ok(Some(alias))) => {
265-
// Check if this alias is shadowing an external subcommand
265+
// Check if a user-defined alias is shadowing an external subcommand
266266
// (binary of the form `cargo-<subcommand>`)
267267
// Currently this is only a warning, but after a transition period this will become
268268
// a hard error.
269-
if let Some(path) = super::find_external_subcommand(config, cmd) {
270-
config.shell().warn(format!(
269+
if super::builtin_aliases_execs(cmd).is_none() {
270+
if let Some(path) = super::find_external_subcommand(config, cmd) {
271+
config.shell().warn(format!(
271272
"\
272273
user-defined alias `{}` is shadowing an external subcommand found at: `{}`
273274
This was previously accepted but is being phased out; it will become a hard error in a future release.
274275
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.",
275276
cmd,
276277
path.display(),
277278
))?;
279+
}
278280
}
279281

280282
let mut alias = alias

tests/testsuite/cargo_alias_config.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,30 @@ fn dependent_alias() {
150150
.run();
151151
}
152152

153+
#[cargo_test]
154+
fn builtin_alias_shadowing_external_subcommand() {
155+
let p = project()
156+
.file("Cargo.toml", &basic_bin_manifest("foo"))
157+
.file("src/main.rs", "fn main() {}")
158+
.executable("cargo-t", "")
159+
.build();
160+
161+
let mut paths: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect();
162+
paths.push(p.root());
163+
let path = env::join_paths(paths).unwrap();
164+
165+
p.cargo("t")
166+
.env("PATH", &path)
167+
.with_stderr(
168+
"\
169+
[COMPILING] foo v0.5.0 [..]
170+
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
171+
[RUNNING] unittests src/main.rs [..]
172+
",
173+
)
174+
.run();
175+
}
176+
153177
#[cargo_test]
154178
fn alias_shadowing_external_subcommand() {
155179
let echo = echo_subcommand();

0 commit comments

Comments
 (0)