diff --git a/src/cargo/core/registry.rs b/src/cargo/core/registry.rs index 9bc4d82025c..e751af4cdf5 100644 --- a/src/cargo/core/registry.rs +++ b/src/cargo/core/registry.rs @@ -22,6 +22,7 @@ use crate::sources::source::SourceMap; use crate::util::errors::CargoResult; use crate::util::interning::InternedString; use crate::util::{CanonicalUrl, GlobalContext}; +use annotate_snippets::{Group, Level}; use anyhow::{Context as _, bail}; use tracing::{debug, trace}; use url::Url; @@ -387,16 +388,20 @@ impl<'gctx> PackageRegistry<'gctx> { unused_fields.push("`default-features`") } if !unused_fields.is_empty() { - let mut shell = self.source_config.gctx().shell(); - shell.warn(format!( - "unused field in patch for `{}`: {}", - dep.package_name(), - unused_fields.join(", ") - ))?; - shell.note(format!( - "configure {} in the `dependencies` entry", - unused_fields.join(", ") - ))?; + self.source_config.gctx().shell().print_report( + &[ + Group::with_title(Level::WARNING.secondary_title(format!( + "unused field in patch for `{}`: {}", + dep.package_name(), + unused_fields.join(", ") + ))), + Group::with_title(Level::NOTE.secondary_title(format!( + "configure {} in the `dependencies` entry", + unused_fields.join(", ") + ))), + ], + false, + )?; } // Go straight to the source for resolving `dep`. Load it as we diff --git a/src/cargo/ops/cargo_package/vcs.rs b/src/cargo/ops/cargo_package/vcs.rs index 9692828ad34..2ef8e59d4bd 100644 --- a/src/cargo/ops/cargo_package/vcs.rs +++ b/src/cargo/ops/cargo_package/vcs.rs @@ -4,6 +4,7 @@ use crate::core::{Package, Workspace}; use crate::ops::PackageOpts; use crate::sources::PathEntry; use crate::{CargoResult, GlobalContext}; +use annotate_snippets::{Group, Level}; use anyhow::Context; use cargo_util::paths; use gix::bstr::ByteSlice; @@ -158,20 +159,26 @@ fn warn_symlink_checked_out_as_plain_text_file( } if src_files.iter().any(|f| f.maybe_plain_text_symlink()) { - let mut shell = gctx.shell(); - shell.warn(format_args!( - "found symbolic links that may be checked out as regular files for git repo at `{}/`\n\ - This might cause the `.crate` file to include incorrect or incomplete files", - repo.workdir().unwrap().display(), - ))?; - let extra_note = if cfg!(windows) { - "\nAnd on Windows, enable the Developer Mode to support symlinks" - } else { - "" + let msg = format!( + "found symbolic links that may be checked out as regular files for git repo at `{}/`", + repo.workdir().unwrap().display() + ); + let mut notes = vec![ + Group::with_title(Level::WARNING.secondary_title(msg)), + Group::with_title(Level::NOTE.secondary_title( + "this might cause the `.crate` file to include incorrect or incomplete files", + )), + Group::with_title( + Level::HELP + .secondary_title("to avoid this, set the Git config `core.symlinks` to `true`"), + ), + ]; + if cfg!(windows) { + notes.push(Group::with_title(Level::HELP.secondary_title( + "on Windows, enable the Developer Mode to support symlinks", + ))); }; - shell.note(format_args!( - "to avoid this, set the Git config `core.symlinks` to `true`{extra_note}", - ))?; + gctx.shell().print_report(¬es, false)?; } Ok(()) diff --git a/src/cargo/sources/registry/mod.rs b/src/cargo/sources/registry/mod.rs index 26e6d89193a..929c068d70b 100644 --- a/src/cargo/sources/registry/mod.rs +++ b/src/cargo/sources/registry/mod.rs @@ -191,6 +191,7 @@ use std::io::Write; use std::path::{Path, PathBuf}; use std::task::{Poll, ready}; +use annotate_snippets::{Group, Level}; use anyhow::Context as _; use cargo_util::paths::{self, exclude_from_backups_and_indexing}; use flate2::read::GzDecoder; @@ -832,10 +833,17 @@ impl<'gctx> Source for RegistrySource<'gctx> { .expect("--precise in use"); if self.selected_precise_yanked.insert((name, version.clone())) { let mut shell = self.gctx.shell(); - shell.warn(format_args!( - "selected package `{name}@{version}` was yanked by the author" - ))?; - shell.note("if possible, try a compatible non-yanked version")?; + shell.print_report( + &[ + Group::with_title(Level::WARNING.secondary_title(format!( + "selected package `{name}@{version}` was yanked by the author" + ))), + Group::with_title(Level::NOTE.secondary_title( + "if possible, try a compatible non-yanked version", + )), + ], + false, + )?; } } if called { diff --git a/src/cargo/util/context/mod.rs b/src/cargo/util/context/mod.rs index 0062018988a..aa5a220813b 100644 --- a/src/cargo/util/context/mod.rs +++ b/src/cargo/util/context/mod.rs @@ -79,6 +79,7 @@ use crate::util::network::http::configure_http_handle; use crate::util::network::http::http_handle; use crate::util::{CanonicalUrl, closest_msg, internal}; use crate::util::{Filesystem, IntoUrl, IntoUrlWithBase, Rustc}; +use annotate_snippets::{Group, Level}; use anyhow::{Context as _, anyhow, bail, format_err}; use cargo_credential::Secret; use cargo_util::paths; @@ -1582,13 +1583,17 @@ impl GlobalContext { ))?; } } else { - self.shell().warn(format!( - "`{}` is deprecated in favor of `{filename_without_extension}.toml`", - possible.display(), - ))?; - self.shell().note( - format!("if you need to support cargo 1.38 or earlier, you can symlink `{filename_without_extension}` to `{filename_without_extension}.toml`"), - )?; + self.shell().print_report(&[ + Group::with_title( + Level::WARNING.secondary_title(format!( + "`{}` is deprecated in favor of `{filename_without_extension}.toml`", + possible.display(), + ) + )), + Group::with_title(Level::NOTE.secondary_title( + format!("if you need to support cargo 1.38 or earlier, you can symlink `{filename_without_extension}` to `{filename_without_extension}.toml`") + )) + ], false)?; } } diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 69f85846a55..1babf3ea315 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -7450,8 +7450,8 @@ fn git_core_symlinks_false() { p.cargo("package --allow-dirty") .with_stderr_data(str![[r#" [WARNING] found symbolic links that may be checked out as regular files for git repo at `[ROOT]/foo/` -This might cause the `.crate` file to include incorrect or incomplete files -[NOTE] to avoid this, set the Git config `core.symlinks` to `true` +[NOTE] this might cause the `.crate` file to include incorrect or incomplete files +[HELP] to avoid this, set the Git config `core.symlinks` to `true` ... [PACKAGING] bar v0.0.0 ([ROOT]/foo) [PACKAGED] 7 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)