Skip to content

Commit cb41a3f

Browse files
committed
refator: use annotate-snippets style report
1 parent fb0690b commit cb41a3f

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/cargo/ops/common_for_install_and_uninstall.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::path::{Path, PathBuf};
66
use std::rc::Rc;
77
use std::task::Poll;
88

9+
use annotate_snippets::Level;
910
use anyhow::{Context as _, bail, format_err};
1011
use cargo_util::paths;
1112
use cargo_util_schemas::core::PartialVersion;
@@ -553,16 +554,21 @@ pub fn resolve_root(flag: Option<&str>, gctx: &GlobalContext) -> CargoResult<Fil
553554
let definition = p.value().definition.clone();
554555
if matches!(definition, Definition::Path(_)) {
555556
let suggested = format!("{}/", resolved.display());
556-
gctx.shell().warn(format!(
557-
"the `install.root` value `{}` defined in {} without a trailing slash is deprecated; \
558-
a future version of Cargo will treat it as relative to the configuration \
559-
directory. Add a trailing slash (`{}`) to adopt the \
560-
correct behavior and silence this warning. See more at \
561-
https://doc.rust-lang.org/cargo/reference/config.html#config-relative-paths",
562-
resolved.display(),
563-
definition,
564-
suggested
565-
))?;
557+
let notes = vec![
558+
Level::NOTE.message("a future version of Cargo will treat it as relative to the configuration directory"),
559+
Level::HELP.message(format!("add a trailing slash (`{}`) to adopt the correct behavior and silence this warning", suggested)),
560+
Level::NOTE.message("see more at https://doc.rust-lang.org/cargo/reference/config.html#config-relative-paths"),
561+
];
562+
gctx.shell().print_report(
563+
&[Level::WARNING
564+
.secondary_title(format!(
565+
"the `install.root` value `{}` defined in {} without a trailing slash is deprecated",
566+
resolved.display(),
567+
definition
568+
))
569+
.elements(notes.into_iter())],
570+
false,
571+
)?;
566572
}
567573
}
568574
Some(resolved)

tests/testsuite/install.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,11 @@ fn relative_install_location_without_trailing_slash() {
522522
let mut cmd = cargo_process("install --path .");
523523
cmd.cwd(p.root());
524524
cmd.with_stderr_data(str![[r#"
525-
[WARNING] the `install.root` value `t1` defined in [ROOT]/.cargo/config.toml without a trailing slash is deprecated; a future version of Cargo will treat it as relative to the configuration directory. Add a trailing slash (`t1/`) to adopt the correct behavior and silence this warning. See more at https://doc.rust-lang.org/cargo/reference/config.html#config-relative-paths
525+
[WARNING] the `install.root` value `t1` defined in [ROOT]/.cargo/config.toml without a trailing slash is deprecated
526+
|
527+
= [NOTE] a future version of Cargo will treat it as relative to the configuration directory
528+
= [HELP] add a trailing slash (`t1/`) to adopt the correct behavior and silence this warning
529+
= [NOTE] see more at https://doc.rust-lang.org/cargo/reference/config.html#config-relative-paths
526530
[INSTALLING] foo v0.0.1 ([ROOT]/foo)
527531
[COMPILING] foo v0.0.1 ([ROOT]/foo)
528532
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
@@ -622,7 +626,11 @@ fn relative_install_location_with_path_set() {
622626
cmd.cwd(p.root());
623627
cmd.env("PATH", new_path);
624628
cmd.with_stderr_data(str![[r#"
625-
[WARNING] the `install.root` value `t1` defined in [ROOT]/.cargo/config.toml without a trailing slash is deprecated; a future version of Cargo will treat it as relative to the configuration directory. Add a trailing slash (`t1/`) to adopt the correct behavior and silence this warning. See more at https://doc.rust-lang.org/cargo/reference/config.html#config-relative-paths
629+
[WARNING] the `install.root` value `t1` defined in [ROOT]/.cargo/config.toml without a trailing slash is deprecated
630+
|
631+
= [NOTE] a future version of Cargo will treat it as relative to the configuration directory
632+
= [HELP] add a trailing slash (`t1/`) to adopt the correct behavior and silence this warning
633+
= [NOTE] see more at https://doc.rust-lang.org/cargo/reference/config.html#config-relative-paths
626634
[INSTALLING] foo v0.0.1 ([ROOT]/foo)
627635
[COMPILING] foo v0.0.1 ([ROOT]/foo)
628636
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s

0 commit comments

Comments
 (0)