Skip to content

Commit 7a38ef2

Browse files
committed
Try using multiple groups in a report
1 parent 90298ef commit 7a38ef2

File tree

8 files changed

+46
-53
lines changed

8 files changed

+46
-53
lines changed

src/cargo/core/registry.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::sources::source::SourceMap;
2222
use crate::util::errors::CargoResult;
2323
use crate::util::interning::InternedString;
2424
use crate::util::{CanonicalUrl, GlobalContext};
25-
use annotate_snippets::Level;
25+
use annotate_snippets::{Group, Level};
2626
use anyhow::{Context as _, bail};
2727
use tracing::{debug, trace};
2828
use url::Url;
@@ -389,16 +389,17 @@ impl<'gctx> PackageRegistry<'gctx> {
389389
}
390390
if !unused_fields.is_empty() {
391391
self.source_config.gctx().shell().print_report(
392-
&[Level::WARNING
393-
.primary_title(format!(
392+
&[
393+
Group::with_title(Level::WARNING.secondary_title(format!(
394394
"unused field in patch for `{}`: {}",
395395
dep.package_name(),
396396
unused_fields.join(", ")
397-
))
398-
.element(Level::NOTE.message(format!(
397+
))),
398+
Group::with_title(Level::NOTE.secondary_title(format!(
399399
"configure {} in the `dependencies` entry",
400400
unused_fields.join(", ")
401-
)))],
401+
))),
402+
],
402403
false,
403404
)?;
404405
}

src/cargo/ops/cargo_package/vcs.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::core::{Package, Workspace};
44
use crate::ops::PackageOpts;
55
use crate::sources::PathEntry;
66
use crate::{CargoResult, GlobalContext};
7-
use annotate_snippets::Level;
7+
use annotate_snippets::{Group, Level};
88
use anyhow::Context;
99
use cargo_util::paths;
1010
use gix::bstr::ByteSlice;
@@ -164,22 +164,21 @@ fn warn_symlink_checked_out_as_plain_text_file(
164164
repo.workdir().unwrap().display()
165165
);
166166
let mut notes = vec![
167-
Level::NOTE.message(
167+
Group::with_title(Level::WARNING.secondary_title(msg)),
168+
Group::with_title(Level::NOTE.secondary_title(
168169
"this might cause the `.crate` file to include incorrect or incomplete files",
170+
)),
171+
Group::with_title(
172+
Level::HELP
173+
.secondary_title("to avoid this, set the Git config `core.symlinks` to `true`"),
169174
),
170-
Level::HELP.message("to avoid this, set the Git config `core.symlinks` to `true`"),
171175
];
172176
if cfg!(windows) {
173-
notes.push(
174-
Level::HELP.message("on Windows, enable the Developer Mode to support symlinks"),
175-
);
177+
notes.push(Group::with_title(Level::HELP.secondary_title(
178+
"on Windows, enable the Developer Mode to support symlinks",
179+
)));
176180
};
177-
gctx.shell().print_report(
178-
&[Level::WARNING
179-
.secondary_title(msg)
180-
.elements(notes.into_iter())],
181-
false,
182-
)?;
181+
gctx.shell().print_report(&notes, false)?;
183182
}
184183

185184
Ok(())

src/cargo/sources/registry/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ use std::io::Write;
191191
use std::path::{Path, PathBuf};
192192
use std::task::{Poll, ready};
193193

194-
use annotate_snippets::Level;
194+
use annotate_snippets::{Group, Level};
195195
use anyhow::Context as _;
196196
use cargo_util::paths::{self, exclude_from_backups_and_indexing};
197197
use flate2::read::GzDecoder;
@@ -834,14 +834,14 @@ impl<'gctx> Source for RegistrySource<'gctx> {
834834
if self.selected_precise_yanked.insert((name, version.clone())) {
835835
let mut shell = self.gctx.shell();
836836
shell.print_report(
837-
&[Level::WARNING
838-
.primary_title(format!(
837+
&[
838+
Group::with_title(Level::WARNING.secondary_title(format!(
839839
"selected package `{name}@{version}` was yanked by the author"
840-
))
841-
.element(
842-
Level::NOTE
843-
.message("if possible, try a compatible non-yanked version"),
844-
)],
840+
))),
841+
Group::with_title(Level::NOTE.secondary_title(
842+
"if possible, try a compatible non-yanked version",
843+
)),
844+
],
845845
false,
846846
)?;
847847
}

src/cargo/util/context/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ use crate::util::network::http::configure_http_handle;
7979
use crate::util::network::http::http_handle;
8080
use crate::util::{CanonicalUrl, closest_msg, internal};
8181
use crate::util::{Filesystem, IntoUrl, IntoUrlWithBase, Rustc};
82-
use annotate_snippets::Level;
82+
use annotate_snippets::{Group, Level};
8383
use anyhow::{Context as _, anyhow, bail, format_err};
8484
use cargo_credential::Secret;
8585
use cargo_util::paths;
@@ -1584,13 +1584,15 @@ impl GlobalContext {
15841584
}
15851585
} else {
15861586
self.shell().print_report(&[
1587-
Level::WARNING.primary_title(
1588-
format!(
1589-
"`{}` is deprecated in favor of `{filename_without_extension}.toml`",
1590-
possible.display(),
1591-
)).element(Level::NOTE.message(
1592-
format!("if you need to support cargo 1.38 or earlier, you can symlink `{filename_without_extension}` to `{filename_without_extension}.toml`")))
1593-
1587+
Group::with_title(
1588+
Level::WARNING.secondary_title(format!(
1589+
"`{}` is deprecated in favor of `{filename_without_extension}.toml`",
1590+
possible.display(),
1591+
)
1592+
)),
1593+
Group::with_title(Level::NOTE.secondary_title(
1594+
format!("if you need to support cargo 1.38 or earlier, you can symlink `{filename_without_extension}` to `{filename_without_extension}.toml`")
1595+
))
15941596
], false)?;
15951597
}
15961598
}

tests/testsuite/config.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ f1 = 1
294294
let output = read_output(gctx);
295295
let expected = str![[r#"
296296
[WARNING] `[ROOT]/.cargo/config` is deprecated in favor of `config.toml`
297-
|
298-
= [NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
297+
[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
299298
300299
"#]];
301300
assert_e2e().eq(&output, expected);
@@ -315,8 +314,7 @@ f1 = 1
315314
p.cargo("-vV")
316315
.with_stderr_data(str![[r#"
317316
[WARNING] `[ROOT]/home/.cargo/config` is deprecated in favor of `config.toml`
318-
|
319-
= [NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
317+
[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
320318
321319
"#]])
322320
.run();

tests/testsuite/package.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7450,9 +7450,8 @@ fn git_core_symlinks_false() {
74507450
p.cargo("package --allow-dirty")
74517451
.with_stderr_data(str![[r#"
74527452
[WARNING] found symbolic links that may be checked out as regular files for git repo at `[ROOT]/foo/`
7453-
|
7454-
= [NOTE] this might cause the `.crate` file to include incorrect or incomplete files
7455-
= [HELP] to avoid this, set the Git config `core.symlinks` to `true`
7453+
[NOTE] this might cause the `.crate` file to include incorrect or incomplete files
7454+
[HELP] to avoid this, set the Git config `core.symlinks` to `true`
74567455
...
74577456
[PACKAGING] bar v0.0.0 ([ROOT]/foo)
74587457
[PACKAGED] 7 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)

tests/testsuite/patch.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,7 @@ fn add_patch_with_features() {
931931
p.cargo("check")
932932
.with_stderr_data(str![[r#"
933933
[WARNING] unused field in patch for `bar`: `features`
934-
|
935-
= [NOTE] configure `features` in the `dependencies` entry
934+
[NOTE] configure `features` in the `dependencies` entry
936935
[UPDATING] `dummy-registry` index
937936
[LOCKING] 1 package to latest compatible version
938937
[CHECKING] bar v0.1.0 ([ROOT]/foo/bar)
@@ -944,8 +943,7 @@ fn add_patch_with_features() {
944943
p.cargo("check")
945944
.with_stderr_data(str![[r#"
946945
[WARNING] unused field in patch for `bar`: `features`
947-
|
948-
= [NOTE] configure `features` in the `dependencies` entry
946+
[NOTE] configure `features` in the `dependencies` entry
949947
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
950948
951949
"#]])
@@ -981,8 +979,7 @@ fn add_patch_with_setting_default_features() {
981979
p.cargo("check")
982980
.with_stderr_data(str![[r#"
983981
[WARNING] unused field in patch for `bar`: `features`, `default-features`
984-
|
985-
= [NOTE] configure `features`, `default-features` in the `dependencies` entry
982+
[NOTE] configure `features`, `default-features` in the `dependencies` entry
986983
[UPDATING] `dummy-registry` index
987984
[LOCKING] 1 package to latest compatible version
988985
[CHECKING] bar v0.1.0 ([ROOT]/foo/bar)
@@ -994,8 +991,7 @@ fn add_patch_with_setting_default_features() {
994991
p.cargo("check")
995992
.with_stderr_data(str![[r#"
996993
[WARNING] unused field in patch for `bar`: `features`, `default-features`
997-
|
998-
= [NOTE] configure `features`, `default-features` in the `dependencies` entry
994+
[NOTE] configure `features`, `default-features` in the `dependencies` entry
999995
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1000996
1001997
"#]])

tests/testsuite/update.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,8 +1438,7 @@ fn precise_yanked() {
14381438
.with_stderr_data(str![[r#"
14391439
[UPDATING] `dummy-registry` index
14401440
[WARNING] selected package `[email protected]` was yanked by the author
1441-
|
1442-
= [NOTE] if possible, try a compatible non-yanked version
1441+
[NOTE] if possible, try a compatible non-yanked version
14431442
[UPDATING] bar v0.1.0 -> v0.1.1
14441443
14451444
"#]])
@@ -1479,8 +1478,7 @@ fn precise_yanked_multiple_presence() {
14791478
.with_stderr_data(str![[r#"
14801479
[UPDATING] `dummy-registry` index
14811480
[WARNING] selected package `[email protected]` was yanked by the author
1482-
|
1483-
= [NOTE] if possible, try a compatible non-yanked version
1481+
[NOTE] if possible, try a compatible non-yanked version
14841482
[UPDATING] bar v0.1.0 -> v0.1.1
14851483
14861484
"#]])

0 commit comments

Comments
 (0)