Skip to content

Commit f71caeb

Browse files
authored
More warning conversions (#16143)
Yet another small part of #15944
2 parents b118df4 + 1f9d059 commit f71caeb

File tree

5 files changed

+66
-18
lines changed

5 files changed

+66
-18
lines changed

src/bin/cargo/commands/tree.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::cli;
22
use crate::command_prelude::*;
3+
use annotate_snippets::Level;
34
use anyhow::{bail, format_err};
45
use cargo::core::dependency::DepKind;
56
use cargo::ops::Packages;
@@ -141,10 +142,16 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
141142

142143
let no_dedupe = args.flag("no-dedupe") || args.flag("all");
143144
if args.flag("all") {
144-
gctx.shell().warn(
145-
"The `cargo tree` --all flag has been changed to --no-dedupe, \
146-
and may be removed in a future version.\n\
147-
If you are looking to display all workspace members, use the --workspace flag.",
145+
gctx.shell().print_report(
146+
&[Level::WARNING
147+
.secondary_title(
148+
"the `cargo tree` --all flag has been changed to --no-dedupe, \
149+
and may be removed in a future version",
150+
)
151+
.element(Level::HELP.message(
152+
"if you are looking to display all workspace members, use the --workspace flag",
153+
))],
154+
false,
148155
)?;
149156
}
150157

src/cargo/ops/cargo_compile/mod.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ use crate::util::interning::InternedString;
5858
use crate::util::{CargoResult, StableHasher};
5959

6060
mod compile_filter;
61+
use annotate_snippets::Level;
6162
pub use compile_filter::{CompileFilter, FilterRule, LibRule};
6263

6364
pub(super) mod unit_generator;
@@ -230,17 +231,24 @@ pub fn create_bcx<'a, 'gctx>(
230231
match build_config.intent {
231232
UserIntent::Test | UserIntent::Build | UserIntent::Check { .. } | UserIntent::Bench => {
232233
if ws.gctx().get_env("RUST_FLAGS").is_ok() {
233-
gctx.shell()
234-
.warn("ignoring environment variable `RUST_FLAGS`")?;
235-
gctx.shell().note("rust flags are passed via `RUSTFLAGS`")?;
234+
gctx.shell().print_report(
235+
&[Level::WARNING
236+
.secondary_title("ignoring environment variable `RUST_FLAGS`")
237+
.element(Level::HELP.message("rust flags are passed via `RUSTFLAGS`"))],
238+
false,
239+
)?;
236240
}
237241
}
238242
UserIntent::Doc { .. } | UserIntent::Doctest => {
239243
if ws.gctx().get_env("RUSTDOC_FLAGS").is_ok() {
240-
gctx.shell()
241-
.warn("ignoring environment variable `RUSTDOC_FLAGS`")?;
242-
gctx.shell()
243-
.note("rustdoc flags are passed via `RUSTDOCFLAGS`")?;
244+
gctx.shell().print_report(
245+
&[Level::WARNING
246+
.secondary_title("ignoring environment variable `RUSTDOC_FLAGS`")
247+
.element(
248+
Level::HELP.message("rustdoc flags are passed via `RUSTDOCFLAGS`"),
249+
)],
250+
false,
251+
)?;
244252
}
245253
}
246254
}

tests/testsuite/cargo_tree/dupe/mod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::prelude::*;
22
use cargo_test_support::file;
33
use cargo_test_support::project;
44
use cargo_test_support::registry::Package;
5+
use cargo_test_support::str;
56

67
#[cargo_test]
78
fn case() {
@@ -34,3 +35,34 @@ fn case() {
3435
.stdout_eq(file!["stdout.term.svg"])
3536
.stderr_eq(file!["stderr.term.svg"]);
3637
}
38+
39+
#[cargo_test]
40+
fn all_flag() {
41+
Package::new("a", "1.0.0").dep("b", "1.0").publish();
42+
Package::new("b", "1.0.0").dep("c", "1.0").publish();
43+
Package::new("c", "1.0.0").publish();
44+
45+
let p = project()
46+
.file(
47+
"Cargo.toml",
48+
r#"
49+
[package]
50+
name = "foo"
51+
version = "0.1.0"
52+
53+
[dependencies]
54+
a = "1.0"
55+
b = "1.0"
56+
"#,
57+
)
58+
.file("src/lib.rs", "")
59+
.file("build.rs", "fn main() {}")
60+
.build();
61+
62+
p.cargo("tree --all").with_stderr_data(str![[r#"
63+
[WARNING] the `cargo tree` --all flag has been changed to --no-dedupe, and may be removed in a future version
64+
|
65+
= [HELP] if you are looking to display all workspace members, use the --workspace flag
66+
...
67+
"#]]).run();
68+
}

tests/testsuite/rustdocflags.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ fn rustdocflags_misspelled() {
116116
.env("RUSTDOC_FLAGS", "foo")
117117
.with_stderr_data(str![[r#"
118118
[WARNING] ignoring environment variable `RUSTDOC_FLAGS`
119-
[NOTE] rustdoc flags are passed via `RUSTDOCFLAGS`
119+
|
120+
= [HELP] rustdoc flags are passed via `RUSTDOCFLAGS`
120121
...
121122
"#]])
122123
.run();

tests/testsuite/rustflags.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,13 +1441,12 @@ fn env_rustflags_misspelled() {
14411441
for cmd in &["check", "build", "run", "test", "bench"] {
14421442
p.cargo(cmd)
14431443
.env("RUST_FLAGS", "foo")
1444-
.with_stderr_data(
1445-
"\
1444+
.with_stderr_data(str![[r#"
14461445
[WARNING] ignoring environment variable `RUST_FLAGS`
1447-
[NOTE] rust flags are passed via `RUSTFLAGS`
1446+
|
1447+
= [HELP] rust flags are passed via `RUSTFLAGS`
14481448
...
1449-
",
1450-
)
1449+
"#]])
14511450
.run();
14521451
}
14531452
}
@@ -1473,7 +1472,8 @@ fn env_rustflags_misspelled_build_script() {
14731472
.env("RUST_FLAGS", "foo")
14741473
.with_stderr_data(str![[r#"
14751474
[WARNING] ignoring environment variable `RUST_FLAGS`
1476-
[NOTE] rust flags are passed via `RUSTFLAGS`
1475+
|
1476+
= [HELP] rust flags are passed via `RUSTFLAGS`
14771477
[COMPILING] foo v0.0.1 ([ROOT]/foo)
14781478
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
14791479

0 commit comments

Comments
 (0)