diff --git a/src/bin/cargo/commands/tree.rs b/src/bin/cargo/commands/tree.rs index 53569e8f7f7..e54b8b02078 100644 --- a/src/bin/cargo/commands/tree.rs +++ b/src/bin/cargo/commands/tree.rs @@ -1,5 +1,6 @@ use crate::cli; use crate::command_prelude::*; +use annotate_snippets::Level; use anyhow::{bail, format_err}; use cargo::core::dependency::DepKind; use cargo::ops::Packages; @@ -141,10 +142,16 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult { let no_dedupe = args.flag("no-dedupe") || args.flag("all"); if args.flag("all") { - gctx.shell().warn( - "The `cargo tree` --all flag has been changed to --no-dedupe, \ - and may be removed in a future version.\n\ - If you are looking to display all workspace members, use the --workspace flag.", + gctx.shell().print_report( + &[Level::WARNING + .secondary_title( + "the `cargo tree` --all flag has been changed to --no-dedupe, \ + and may be removed in a future version", + ) + .element(Level::HELP.message( + "if you are looking to display all workspace members, use the --workspace flag", + ))], + false, )?; } diff --git a/src/cargo/ops/cargo_compile/mod.rs b/src/cargo/ops/cargo_compile/mod.rs index f8dc0df07cb..d219322d240 100644 --- a/src/cargo/ops/cargo_compile/mod.rs +++ b/src/cargo/ops/cargo_compile/mod.rs @@ -58,6 +58,7 @@ use crate::util::interning::InternedString; use crate::util::{CargoResult, StableHasher}; mod compile_filter; +use annotate_snippets::Level; pub use compile_filter::{CompileFilter, FilterRule, LibRule}; pub(super) mod unit_generator; @@ -230,17 +231,24 @@ pub fn create_bcx<'a, 'gctx>( match build_config.intent { UserIntent::Test | UserIntent::Build | UserIntent::Check { .. } | UserIntent::Bench => { if ws.gctx().get_env("RUST_FLAGS").is_ok() { - gctx.shell() - .warn("ignoring environment variable `RUST_FLAGS`")?; - gctx.shell().note("rust flags are passed via `RUSTFLAGS`")?; + gctx.shell().print_report( + &[Level::WARNING + .secondary_title("ignoring environment variable `RUST_FLAGS`") + .element(Level::HELP.message("rust flags are passed via `RUSTFLAGS`"))], + false, + )?; } } UserIntent::Doc { .. } | UserIntent::Doctest => { if ws.gctx().get_env("RUSTDOC_FLAGS").is_ok() { - gctx.shell() - .warn("ignoring environment variable `RUSTDOC_FLAGS`")?; - gctx.shell() - .note("rustdoc flags are passed via `RUSTDOCFLAGS`")?; + gctx.shell().print_report( + &[Level::WARNING + .secondary_title("ignoring environment variable `RUSTDOC_FLAGS`") + .element( + Level::HELP.message("rustdoc flags are passed via `RUSTDOCFLAGS`"), + )], + false, + )?; } } } diff --git a/tests/testsuite/cargo_tree/dupe/mod.rs b/tests/testsuite/cargo_tree/dupe/mod.rs index 165d1f8e938..fb468fb6399 100644 --- a/tests/testsuite/cargo_tree/dupe/mod.rs +++ b/tests/testsuite/cargo_tree/dupe/mod.rs @@ -2,6 +2,7 @@ use crate::prelude::*; use cargo_test_support::file; use cargo_test_support::project; use cargo_test_support::registry::Package; +use cargo_test_support::str; #[cargo_test] fn case() { @@ -34,3 +35,34 @@ fn case() { .stdout_eq(file!["stdout.term.svg"]) .stderr_eq(file!["stderr.term.svg"]); } + +#[cargo_test] +fn all_flag() { + Package::new("a", "1.0.0").dep("b", "1.0").publish(); + Package::new("b", "1.0.0").dep("c", "1.0").publish(); + Package::new("c", "1.0.0").publish(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + + [dependencies] + a = "1.0" + b = "1.0" + "#, + ) + .file("src/lib.rs", "") + .file("build.rs", "fn main() {}") + .build(); + + p.cargo("tree --all").with_stderr_data(str![[r#" +[WARNING] the `cargo tree` --all flag has been changed to --no-dedupe, and may be removed in a future version + | + = [HELP] if you are looking to display all workspace members, use the --workspace flag +... +"#]]).run(); +} diff --git a/tests/testsuite/rustdocflags.rs b/tests/testsuite/rustdocflags.rs index ade2490a003..588c5aa5f95 100644 --- a/tests/testsuite/rustdocflags.rs +++ b/tests/testsuite/rustdocflags.rs @@ -116,7 +116,8 @@ fn rustdocflags_misspelled() { .env("RUSTDOC_FLAGS", "foo") .with_stderr_data(str![[r#" [WARNING] ignoring environment variable `RUSTDOC_FLAGS` -[NOTE] rustdoc flags are passed via `RUSTDOCFLAGS` + | + = [HELP] rustdoc flags are passed via `RUSTDOCFLAGS` ... "#]]) .run(); diff --git a/tests/testsuite/rustflags.rs b/tests/testsuite/rustflags.rs index 5f401ba60cc..6d7c68f9e42 100644 --- a/tests/testsuite/rustflags.rs +++ b/tests/testsuite/rustflags.rs @@ -1441,13 +1441,12 @@ fn env_rustflags_misspelled() { for cmd in &["check", "build", "run", "test", "bench"] { p.cargo(cmd) .env("RUST_FLAGS", "foo") - .with_stderr_data( - "\ + .with_stderr_data(str![[r#" [WARNING] ignoring environment variable `RUST_FLAGS` -[NOTE] rust flags are passed via `RUSTFLAGS` + | + = [HELP] rust flags are passed via `RUSTFLAGS` ... -", - ) +"#]]) .run(); } } @@ -1473,7 +1472,8 @@ fn env_rustflags_misspelled_build_script() { .env("RUST_FLAGS", "foo") .with_stderr_data(str![[r#" [WARNING] ignoring environment variable `RUST_FLAGS` -[NOTE] rust flags are passed via `RUSTFLAGS` + | + = [HELP] rust flags are passed via `RUSTFLAGS` [COMPILING] foo v0.0.1 ([ROOT]/foo) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s