Skip to content

Commit 4581ba8

Browse files
committed
Port cli shadowing warnings
1 parent bc38953 commit 4581ba8

File tree

3 files changed

+54
-31
lines changed

3 files changed

+54
-31
lines changed

src/bin/cargo/cli.rs

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use annotate_snippets::Level;
12
use anyhow::{Context as _, anyhow};
23
use cargo::core::{CliUnstable, features};
34
use cargo::util::context::TermConfig;
@@ -318,26 +319,40 @@ To pass the arguments to the subcommand, remove `--`",
318319
// a hard error.
319320
if super::builtin_aliases_execs(cmd).is_none() {
320321
if let Some(path) = super::find_external_subcommand(gctx, cmd) {
321-
gctx.shell().warn(format!(
322-
"\
323-
user-defined alias `{}` is shadowing an external subcommand found at: `{}`
324-
This was previously accepted but is being phased out; it will become a hard error in a future release.
325-
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.",
326-
cmd,
327-
path.display(),
328-
))?;
322+
gctx.shell().print_report(
323+
&[
324+
Level::WARNING.secondary_title(format!(
325+
"user-defined alias `{}` is shadowing an external subcommand found at `{}`",
326+
cmd,
327+
path.display()
328+
)).element(
329+
Level::NOTE.message(
330+
"this was previously accepted but will become a hard error in the future; \
331+
see <https://github.com/rust-lang/cargo/issues/10049>"
332+
)
333+
)
334+
],
335+
false,
336+
)?;
329337
}
330338
}
331339
if commands::run::is_manifest_command(cmd) {
332340
if gctx.cli_unstable().script {
333341
return Ok((args, GlobalArgs::default()));
334342
} else {
335-
gctx.shell().warn(format_args!(
336-
"\
337-
user-defined alias `{cmd}` has the appearance of a manifest-command
338-
This was previously accepted but will be phased out when `-Zscript` is stabilized.
339-
For more information, see issue #12207 <https://github.com/rust-lang/cargo/issues/12207>."
340-
))?;
343+
gctx.shell().print_report(
344+
&[
345+
Level::WARNING.secondary_title(
346+
format!("user-defined alias `{cmd}` has the appearance of a manifest-command")
347+
).element(
348+
Level::NOTE.message(
349+
"this was previously accepted but will be phased out when `-Zscript` is stabilized; \
350+
see <https://github.com/rust-lang/cargo/issues/12207>"
351+
)
352+
)
353+
],
354+
false
355+
)?;
341356
}
342357
}
343358

@@ -477,12 +492,20 @@ impl Exec {
477492
Self::Manifest(cmd) => {
478493
let ext_path = super::find_external_subcommand(gctx, &cmd);
479494
if !gctx.cli_unstable().script && ext_path.is_some() {
480-
gctx.shell().warn(format_args!(
481-
"\
482-
external subcommand `{cmd}` has the appearance of a manifest-command
483-
This was previously accepted but will be phased out when `-Zscript` is stabilized.
484-
For more information, see issue #12207 <https://github.com/rust-lang/cargo/issues/12207>.",
485-
))?;
495+
gctx.shell().print_report(
496+
&[
497+
Level::WARNING.secondary_title(
498+
format!("external subcommand `{cmd}` has the appearance of a manifest-command")
499+
).element(
500+
Level::NOTE.message(
501+
"this was previously accepted but will be phased out when `-Zscript` is stabilized; \
502+
see <https://github.com/rust-lang/cargo/issues/12207>"
503+
)
504+
)
505+
],
506+
false
507+
)?;
508+
486509
Self::External(cmd).exec(gctx, subcommand_args)
487510
} else {
488511
let ext_args: Vec<OsString> = subcommand_args

tests/testsuite/cargo_alias_config.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ fn alias_shadowing_external_subcommand() {
190190
p.cargo("echo")
191191
.env("PATH", &path)
192192
.with_stderr_data(str![[r#"
193-
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
194-
This was previously accepted but is being phased out; it will become a hard error in a future release.
195-
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.
193+
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
194+
|
195+
= [NOTE] this was previously accepted but will become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/10049>
196196
[COMPILING] foo v0.5.0 ([ROOT]/foo)
197197
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
198198
@@ -225,9 +225,9 @@ fn default_args_alias() {
225225
.env("PATH", &path)
226226
.with_status(101)
227227
.with_stderr_data(str![[r#"
228-
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
229-
This was previously accepted but is being phased out; it will become a hard error in a future release.
230-
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.
228+
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
229+
|
230+
= [NOTE] this was previously accepted but will become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/10049>
231231
[ERROR] alias echo has unresolvable recursive definition: echo -> echo
232232
233233
"#]])
@@ -237,9 +237,9 @@ For more information, see issue #10049 <https://github.com/rust-lang/cargo/issue
237237
.env("PATH", &path)
238238
.with_status(101)
239239
.with_stderr_data(str![[r#"
240-
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
241-
This was previously accepted but is being phased out; it will become a hard error in a future release.
242-
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.
240+
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
241+
|
242+
= [NOTE] this was previously accepted but will become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/10049>
243243
[ERROR] alias test-1 has unresolvable recursive definition: test-1 -> echo -> echo
244244
245245
"#]])

tests/testsuite/script/cargo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ fn warn_when_plugin_masks_manifest_on_stable() {
197197
.with_stdout_data("")
198198
.with_stderr_data(str![[r#"
199199
[WARNING] external subcommand `echo.rs` has the appearance of a manifest-command
200-
This was previously accepted but will be phased out when `-Zscript` is stabilized.
201-
For more information, see issue #12207 <https://github.com/rust-lang/cargo/issues/12207>.
200+
|
201+
= [NOTE] this was previously accepted but will be phased out when `-Zscript` is stabilized; see <https://github.com/rust-lang/cargo/issues/12207>
202202
203203
"#]])
204204
.run();

0 commit comments

Comments
 (0)