Skip to content

Commit ed20c81

Browse files
authored
Convert a few more diagnostics to reports (#16066)
Here I'm continuing to slowly work through multi-part diagnostics and convert them to reports. Like #16035, this converts a warning + note into a single `Group` with a warning title containing note elements. Based on [this comment](#16035 (comment)) I'm not sure if this is actually what you want, mostly because these notes are typically shorter than the ones in #16035. For comparison, I'll open another PR that does multiple groups. Edit: #16065 This is part of #15944
2 parents 3e9b30d + c8ceda2 commit ed20c81

File tree

8 files changed

+74
-42
lines changed

8 files changed

+74
-42
lines changed

src/cargo/core/registry.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +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;
2526
use anyhow::{Context as _, bail};
2627
use tracing::{debug, trace};
2728
use url::Url;
@@ -387,16 +388,19 @@ impl<'gctx> PackageRegistry<'gctx> {
387388
unused_fields.push("`default-features`")
388389
}
389390
if !unused_fields.is_empty() {
390-
let mut shell = self.source_config.gctx().shell();
391-
shell.warn(format!(
392-
"unused field in patch for `{}`: {}",
393-
dep.package_name(),
394-
unused_fields.join(", ")
395-
))?;
396-
shell.note(format!(
397-
"configure {} in the `dependencies` entry",
398-
unused_fields.join(", ")
399-
))?;
391+
self.source_config.gctx().shell().print_report(
392+
&[Level::WARNING
393+
.secondary_title(format!(
394+
"unused field in patch for `{}`: {}",
395+
dep.package_name(),
396+
unused_fields.join(", ")
397+
))
398+
.element(Level::HELP.message(format!(
399+
"configure {} in the `dependencies` entry",
400+
unused_fields.join(", ")
401+
)))],
402+
false,
403+
)?;
400404
}
401405

402406
// Go straight to the source for resolving `dep`. Load it as we

src/cargo/ops/cargo_package/vcs.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +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;
78
use anyhow::Context;
89
use cargo_util::paths;
910
use gix::bstr::ByteSlice;
@@ -158,20 +159,27 @@ fn warn_symlink_checked_out_as_plain_text_file(
158159
}
159160

160161
if src_files.iter().any(|f| f.maybe_plain_text_symlink()) {
161-
let mut shell = gctx.shell();
162-
shell.warn(format_args!(
163-
"found symbolic links that may be checked out as regular files for git repo at `{}/`\n\
164-
This might cause the `.crate` file to include incorrect or incomplete files",
165-
repo.workdir().unwrap().display(),
166-
))?;
167-
let extra_note = if cfg!(windows) {
168-
"\nAnd on Windows, enable the Developer Mode to support symlinks"
169-
} else {
170-
""
162+
let msg = format!(
163+
"found symbolic links that may be checked out as regular files for git repo at `{}/`",
164+
repo.workdir().unwrap().display()
165+
);
166+
let mut notes = vec![
167+
Level::NOTE.message(
168+
"this might cause the `.crate` file to include incorrect or incomplete files",
169+
),
170+
Level::HELP.message("to avoid this, set the Git config `core.symlinks` to `true`"),
171+
];
172+
if cfg!(windows) {
173+
notes.push(
174+
Level::HELP.message("on Windows, enable the Developer Mode to support symlinks"),
175+
);
171176
};
172-
shell.note(format_args!(
173-
"to avoid this, set the Git config `core.symlinks` to `true`{extra_note}",
174-
))?;
177+
gctx.shell().print_report(
178+
&[Level::WARNING
179+
.secondary_title(msg)
180+
.elements(notes.into_iter())],
181+
false,
182+
)?;
175183
}
176184

177185
Ok(())

src/cargo/sources/registry/mod.rs

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

194+
use annotate_snippets::Level;
194195
use anyhow::Context as _;
195196
use cargo_util::paths::{self, exclude_from_backups_and_indexing};
196197
use flate2::read::GzDecoder;
@@ -832,10 +833,17 @@ impl<'gctx> Source for RegistrySource<'gctx> {
832833
.expect("--precise <yanked-version> in use");
833834
if self.selected_precise_yanked.insert((name, version.clone())) {
834835
let mut shell = self.gctx.shell();
835-
shell.warn(format_args!(
836-
"selected package `{name}@{version}` was yanked by the author"
837-
))?;
838-
shell.note("if possible, try a compatible non-yanked version")?;
836+
shell.print_report(
837+
&[Level::WARNING
838+
.secondary_title(format!(
839+
"selected package `{name}@{version}` was yanked by the author"
840+
))
841+
.element(
842+
Level::HELP
843+
.message("if possible, try a compatible non-yanked version"),
844+
)],
845+
false,
846+
)?;
839847
}
840848
}
841849
if called {

src/cargo/util/context/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +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;
8283
use anyhow::{Context as _, anyhow, bail, format_err};
8384
use cargo_credential::Secret;
8485
use cargo_util::paths;
@@ -1541,13 +1542,15 @@ impl GlobalContext {
15411542
))?;
15421543
}
15431544
} else {
1544-
self.shell().warn(format!(
1545+
self.shell().print_report(&[
1546+
Level::WARNING.secondary_title(
1547+
format!(
15451548
"`{}` is deprecated in favor of `{filename_without_extension}.toml`",
15461549
possible.display(),
1547-
))?;
1548-
self.shell().note(
1549-
format!("if you need to support cargo 1.38 or earlier, you can symlink `{filename_without_extension}` to `{filename_without_extension}.toml`"),
1550-
)?;
1550+
)).element(Level::HELP.message(
1551+
format!("if you need to support cargo 1.38 or earlier, you can symlink `{filename_without_extension}` to `{filename_without_extension}.toml`")))
1552+
1553+
], false)?;
15511554
}
15521555
}
15531556

tests/testsuite/config.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ 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-
[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
297+
|
298+
= [HELP] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
298299
299300
"#]];
300301
assert_e2e().eq(&output, expected);
@@ -314,7 +315,8 @@ f1 = 1
314315
p.cargo("-vV")
315316
.with_stderr_data(str![[r#"
316317
[WARNING] `[ROOT]/home/.cargo/config` is deprecated in favor of `config.toml`
317-
[NOTE] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
318+
|
319+
= [HELP] if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
318320
319321
"#]])
320322
.run();

tests/testsuite/package.rs

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

tests/testsuite/patch.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,8 @@ 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-
[NOTE] configure `features` in the `dependencies` entry
934+
|
935+
= [HELP] configure `features` in the `dependencies` entry
935936
[UPDATING] `dummy-registry` index
936937
[LOCKING] 1 package to latest compatible version
937938
[CHECKING] bar v0.1.0 ([ROOT]/foo/bar)
@@ -943,7 +944,8 @@ fn add_patch_with_features() {
943944
p.cargo("check")
944945
.with_stderr_data(str![[r#"
945946
[WARNING] unused field in patch for `bar`: `features`
946-
[NOTE] configure `features` in the `dependencies` entry
947+
|
948+
= [HELP] configure `features` in the `dependencies` entry
947949
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
948950
949951
"#]])
@@ -979,7 +981,8 @@ fn add_patch_with_setting_default_features() {
979981
p.cargo("check")
980982
.with_stderr_data(str![[r#"
981983
[WARNING] unused field in patch for `bar`: `features`, `default-features`
982-
[NOTE] configure `features`, `default-features` in the `dependencies` entry
984+
|
985+
= [HELP] configure `features`, `default-features` in the `dependencies` entry
983986
[UPDATING] `dummy-registry` index
984987
[LOCKING] 1 package to latest compatible version
985988
[CHECKING] bar v0.1.0 ([ROOT]/foo/bar)
@@ -991,7 +994,8 @@ fn add_patch_with_setting_default_features() {
991994
p.cargo("check")
992995
.with_stderr_data(str![[r#"
993996
[WARNING] unused field in patch for `bar`: `features`, `default-features`
994-
[NOTE] configure `features`, `default-features` in the `dependencies` entry
997+
|
998+
= [HELP] configure `features`, `default-features` in the `dependencies` entry
995999
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
9961000
9971001
"#]])

tests/testsuite/update.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,8 @@ fn precise_yanked() {
14381438
.with_stderr_data(str![[r#"
14391439
[UPDATING] `dummy-registry` index
14401440
[WARNING] selected package `bar@0.1.1` was yanked by the author
1441-
[NOTE] if possible, try a compatible non-yanked version
1441+
|
1442+
= [HELP] if possible, try a compatible non-yanked version
14421443
[UPDATING] bar v0.1.0 -> v0.1.1
14431444
14441445
"#]])
@@ -1478,7 +1479,8 @@ fn precise_yanked_multiple_presence() {
14781479
.with_stderr_data(str![[r#"
14791480
[UPDATING] `dummy-registry` index
14801481
[WARNING] selected package `bar@0.1.1` was yanked by the author
1481-
[NOTE] if possible, try a compatible non-yanked version
1482+
|
1483+
= [HELP] if possible, try a compatible non-yanked version
14821484
[UPDATING] bar v0.1.0 -> v0.1.1
14831485
14841486
"#]])

0 commit comments

Comments
 (0)