Skip to content

Commit 5fe92f0

Browse files
committed
fix(shell): Switch to annotate snippets for warnings
This is part of #15944
1 parent 36bc1d1 commit 5fe92f0

23 files changed

+219
-216
lines changed

src/cargo/core/shell.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ impl Shell {
222222

223223
/// Prints an amber 'warning' message.
224224
pub fn warn<T: fmt::Display>(&mut self, message: T) -> CargoResult<()> {
225-
self.print(&"warning", Some(&message), &WARN, false)
225+
let report = &[annotate_snippets::Group::with_title(
226+
annotate_snippets::Level::WARNING.secondary_title(message.to_string()),
227+
)];
228+
self.print_report(report, false)
226229
}
227230

228231
/// Prints a cyan 'note' message.

tests/testsuite/bad_config.rs

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ fn dev_dependencies2() {
962962
.build();
963963
p.cargo("check").with_stderr_data(str![[r#"
964964
[WARNING] `dev_dependencies` is deprecated in favor of `dev-dependencies` and will not work in the 2024 edition
965-
(in the `foo` package)
965+
(in the `foo` package)
966966
[LOCKING] 1 package to latest compatible version
967967
[CHECKING] foo v0.1.0 ([ROOT]/foo)
968968
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -1077,7 +1077,7 @@ fn build_dependencies2() {
10771077
.build();
10781078
p.cargo("check").with_stderr_data(str![[r#"
10791079
[WARNING] `build_dependencies` is deprecated in favor of `build-dependencies` and will not work in the 2024 edition
1080-
(in the `foo` package)
1080+
(in the `foo` package)
10811081
[LOCKING] 1 package to latest compatible version
10821082
[CHECKING] foo v0.1.0 ([ROOT]/foo)
10831083
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -1185,7 +1185,7 @@ fn lib_crate_type2() {
11851185
p.cargo("check")
11861186
.with_stderr_data(str![[r#"
11871187
[WARNING] `crate_type` is deprecated in favor of `crate-type` and will not work in the 2024 edition
1188-
(in the `foo` library target)
1188+
(in the `foo` library target)
11891189
[CHECKING] foo v0.5.0 ([ROOT]/foo)
11901190
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
11911191
@@ -1276,7 +1276,7 @@ fn bin_crate_type2() {
12761276
p.cargo("check")
12771277
.with_stderr_data(str![[r#"
12781278
[WARNING] `crate_type` is deprecated in favor of `crate-type` and will not work in the 2024 edition
1279-
(in the `foo` binary target)
1279+
(in the `foo` binary target)
12801280
[CHECKING] foo v0.5.0 ([ROOT]/foo)
12811281
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
12821282
@@ -1385,9 +1385,9 @@ fn examples_crate_type2() {
13851385
p.cargo("check")
13861386
.with_stderr_data(str![[r#"
13871387
[WARNING] `crate_type` is deprecated in favor of `crate-type` and will not work in the 2024 edition
1388-
(in the `ex` example target)
1388+
(in the `ex` example target)
13891389
[WARNING] `crate_type` is deprecated in favor of `crate-type` and will not work in the 2024 edition
1390-
(in the `goodbye` example target)
1390+
(in the `goodbye` example target)
13911391
[CHECKING] foo v0.5.0 ([ROOT]/foo)
13921392
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
13931393
@@ -1524,7 +1524,7 @@ fn cargo_platform_build_dependencies2() {
15241524
p.cargo("check")
15251525
.with_stderr_data(str![[r#"
15261526
[WARNING] `build_dependencies` is deprecated in favor of `build-dependencies` and will not work in the 2024 edition
1527-
(in the `[HOST_TARGET]` platform target)
1527+
(in the `[HOST_TARGET]` platform target)
15281528
[LOCKING] 1 package to latest compatible version
15291529
[COMPILING] build v0.5.0 ([ROOT]/foo/build)
15301530
[COMPILING] foo v0.5.0 ([ROOT]/foo)
@@ -1655,7 +1655,7 @@ fn cargo_platform_dev_dependencies2() {
16551655
p.cargo("check")
16561656
.with_stderr_data(str![[r#"
16571657
[WARNING] `dev_dependencies` is deprecated in favor of `dev-dependencies` and will not work in the 2024 edition
1658-
(in the `[HOST_TARGET]` platform target)
1658+
(in the `[HOST_TARGET]` platform target)
16591659
[LOCKING] 1 package to latest compatible version
16601660
[CHECKING] foo v0.5.0 ([ROOT]/foo)
16611661
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -1784,7 +1784,7 @@ fn default_features2() {
17841784

17851785
p.cargo("check").with_stderr_data(str![[r#"
17861786
[WARNING] `default_features` is deprecated in favor of `default-features` and will not work in the 2024 edition
1787-
(in the `a` dependency)
1787+
(in the `a` dependency)
17881788
[LOCKING] 1 package to latest compatible version
17891789
[CHECKING] a v0.1.0 ([ROOT]/foo/a)
17901790
[CHECKING] foo v0.1.0 ([ROOT]/foo)
@@ -1959,7 +1959,7 @@ fn workspace_default_features2() {
19591959
[CHECKING] workspace_only v0.1.0 ([ROOT]/foo/workspace_only)
19601960
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
19611961
[WARNING] [ROOT]/foo/workspace_only/Cargo.toml: `default_features` is deprecated in favor of `default-features` and will not work in the 2024 edition
1962-
(in the `dep_workspace_only` dependency)
1962+
(in the `dep_workspace_only` dependency)
19631963
19641964
"#]]
19651965
.unordered(),
@@ -2070,7 +2070,7 @@ fn lib_proc_macro2() {
20702070
foo.cargo("check")
20712071
.with_stderr_data(str![[r#"
20722072
[WARNING] `proc_macro` is deprecated in favor of `proc-macro` and will not work in the 2024 edition
2073-
(in the `foo` library target)
2073+
(in the `foo` library target)
20742074
[CHECKING] foo v0.1.0 ([ROOT]/foo)
20752075
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
20762076
@@ -2158,7 +2158,7 @@ fn bin_proc_macro2() {
21582158
foo.cargo("check")
21592159
.with_stderr_data(str![[r#"
21602160
[WARNING] `proc_macro` is deprecated in favor of `proc-macro` and will not work in the 2024 edition
2161-
(in the `foo` binary target)
2161+
(in the `foo` binary target)
21622162
[CHECKING] foo v0.5.0 ([ROOT]/foo)
21632163
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
21642164
@@ -3596,22 +3596,22 @@ fn legacy_binary_paths_warnings() {
35963596
p.cargo("check -v")
35973597
.with_stderr_data(str![[r#"
35983598
[WARNING] An explicit [[bin]] section is specified in Cargo.toml which currently
3599-
disables Cargo from automatically inferring other binary targets.
3600-
This inference behavior will change in the Rust 2018 edition and the following
3601-
files will be included as a binary target:
3602-
3603-
* src/main.rs
3604-
3605-
This is likely to break cargo build or cargo test as these files may not be
3606-
ready to be compiled as a binary target today. You can future-proof yourself
3607-
and disable this warning by adding `autobins = false` to your [package]
3608-
section. You may also move the files to a location where Cargo would not
3609-
automatically infer them to be a target, such as in subfolders.
3610-
3611-
For more information on this warning you can consult
3612-
https://github.com/rust-lang/cargo/issues/5330
3599+
disables Cargo from automatically inferring other binary targets.
3600+
This inference behavior will change in the Rust 2018 edition and the following
3601+
files will be included as a binary target:
3602+
3603+
* src/main.rs
3604+
3605+
This is likely to break cargo build or cargo test as these files may not be
3606+
ready to be compiled as a binary target today. You can future-proof yourself
3607+
and disable this warning by adding `autobins = false` to your [package]
3608+
section. You may also move the files to a location where Cargo would not
3609+
automatically infer them to be a target, such as in subfolders.
3610+
3611+
For more information on this warning you can consult
3612+
https://github.com/rust-lang/cargo/issues/5330
36133613
[WARNING] path `src/main.rs` was erroneously implicitly accepted for binary `bar`,
3614-
please set bin.path in Cargo.toml
3614+
please set bin.path in Cargo.toml
36153615
[CHECKING] foo v1.0.0 ([ROOT]/foo)
36163616
[RUNNING] `rustc [..]`
36173617
[RUNNING] `rustc [..]`
@@ -3641,22 +3641,22 @@ please set bin.path in Cargo.toml
36413641
p.cargo("check -v")
36423642
.with_stderr_data(str![[r#"
36433643
[WARNING] An explicit [[bin]] section is specified in Cargo.toml which currently
3644-
disables Cargo from automatically inferring other binary targets.
3645-
This inference behavior will change in the Rust 2018 edition and the following
3646-
files will be included as a binary target:
3647-
3648-
* src/bin/main.rs
3649-
3650-
This is likely to break cargo build or cargo test as these files may not be
3651-
ready to be compiled as a binary target today. You can future-proof yourself
3652-
and disable this warning by adding `autobins = false` to your [package]
3653-
section. You may also move the files to a location where Cargo would not
3654-
automatically infer them to be a target, such as in subfolders.
3655-
3656-
For more information on this warning you can consult
3657-
https://github.com/rust-lang/cargo/issues/5330
3644+
disables Cargo from automatically inferring other binary targets.
3645+
This inference behavior will change in the Rust 2018 edition and the following
3646+
files will be included as a binary target:
3647+
3648+
* src/bin/main.rs
3649+
3650+
This is likely to break cargo build or cargo test as these files may not be
3651+
ready to be compiled as a binary target today. You can future-proof yourself
3652+
and disable this warning by adding `autobins = false` to your [package]
3653+
section. You may also move the files to a location where Cargo would not
3654+
automatically infer them to be a target, such as in subfolders.
3655+
3656+
For more information on this warning you can consult
3657+
https://github.com/rust-lang/cargo/issues/5330
36583658
[WARNING] path `src/bin/main.rs` was erroneously implicitly accepted for binary `bar`,
3659-
please set bin.path in Cargo.toml
3659+
please set bin.path in Cargo.toml
36603660
[CHECKING] foo v1.0.0 ([ROOT]/foo)
36613661
[RUNNING] `rustc [..]`
36623662
[RUNNING] `rustc [..]`
@@ -3685,7 +3685,7 @@ please set bin.path in Cargo.toml
36853685
p.cargo("check -v")
36863686
.with_stderr_data(str![[r#"
36873687
[WARNING] path `src/bar.rs` was erroneously implicitly accepted for binary `bar`,
3688-
please set bin.path in Cargo.toml
3688+
please set bin.path in Cargo.toml
36893689
[CHECKING] foo v1.0.0 ([ROOT]/foo)
36903690
[RUNNING] `rustc [..]`
36913691
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

tests/testsuite/bench.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -716,20 +716,20 @@ fn bench_autodiscover_2015() {
716716
p.cargo("bench bench_basic")
717717
.with_stderr_data(str![[r#"
718718
[WARNING] An explicit [[bench]] section is specified in Cargo.toml which currently
719-
disables Cargo from automatically inferring other benchmark targets.
720-
This inference behavior will change in the Rust 2018 edition and the following
721-
files will be included as a benchmark target:
722-
723-
* [..]bench_basic.rs
724-
725-
This is likely to break cargo build or cargo test as these files may not be
726-
ready to be compiled as a benchmark target today. You can future-proof yourself
727-
and disable this warning by adding `autobenches = false` to your [package]
728-
section. You may also move the files to a location where Cargo would not
729-
automatically infer them to be a target, such as in subfolders.
730-
731-
For more information on this warning you can consult
732-
https://github.com/rust-lang/cargo/issues/5330
719+
disables Cargo from automatically inferring other benchmark targets.
720+
This inference behavior will change in the Rust 2018 edition and the following
721+
files will be included as a benchmark target:
722+
723+
* benches/bench_basic.rs
724+
725+
This is likely to break cargo build or cargo test as these files may not be
726+
ready to be compiled as a benchmark target today. You can future-proof yourself
727+
and disable this warning by adding `autobenches = false` to your [package]
728+
section. You may also move the files to a location where Cargo would not
729+
automatically infer them to be a target, such as in subfolders.
730+
731+
For more information on this warning you can consult
732+
https://github.com/rust-lang/cargo/issues/5330
733733
[COMPILING] foo v0.0.1 ([ROOT]/foo)
734734
[FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s
735735
[RUNNING] [..] (target/release/deps/foo-[HASH][EXE])
@@ -1944,7 +1944,7 @@ fn legacy_bench_name() {
19441944
p.cargo("bench")
19451945
.with_stderr_data(str![[r#"
19461946
[WARNING] path `src/bench.rs` was erroneously implicitly accepted for benchmark `bench`,
1947-
please set bench.path in Cargo.toml
1947+
please set bench.path in Cargo.toml
19481948
[COMPILING] foo v0.1.0 ([ROOT]/foo)
19491949
[FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s
19501950
[RUNNING] unittests src/lib.rs (target/release/deps/foo-[HASH][EXE])

tests/testsuite/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ fn cargo_compile_duplicate_build_targets() {
471471
p.cargo("build")
472472
.with_stderr_data(str![[r#"
473473
[WARNING] file `[ROOT]/foo/src/main.rs` found to be present in multiple build targets:
474-
* `lib` target `main`
475-
* `bin` target `foo`
474+
* `lib` target `main`
475+
* `bin` target `foo`
476476
[COMPILING] foo v0.0.1 ([ROOT]/foo)
477477
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
478478
@@ -1992,7 +1992,7 @@ fn many_crate_types_old_style_lib_location() {
19921992
p.cargo("build")
19931993
.with_stderr_data(str![[r#"
19941994
[WARNING] path `src/foo.rs` was erroneously implicitly accepted for library `foo`,
1995-
please rename the file to `src/lib.rs` or set lib.path in Cargo.toml
1995+
please rename the file to `src/lib.rs` or set lib.path in Cargo.toml
19961996
[COMPILING] foo v0.5.0 ([ROOT]/foo)
19971997
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
19981998

tests/testsuite/build_script_env.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn rustc_bootstrap() {
145145
.with_stderr_data(str![[r#"
146146
[COMPILING] has-dashes v0.0.1 ([ROOT]/foo)
147147
[WARNING] [email protected]: Cannot set `RUSTC_BOOTSTRAP=1` from build script of `has-dashes v0.0.1 ([ROOT]/foo)`.
148-
[NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.
148+
[NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.
149149
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
150150
151151
"#]])
@@ -155,7 +155,7 @@ fn rustc_bootstrap() {
155155
.env("RUSTC_BOOTSTRAP", "has_dashes")
156156
.with_stderr_data(str![[r#"
157157
[WARNING] [email protected]: Cannot set `RUSTC_BOOTSTRAP=1` from build script of `has-dashes v0.0.1 ([ROOT]/foo)`.
158-
[NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.
158+
[NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.
159159
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
160160
161161
"#]])
@@ -190,7 +190,7 @@ fn rustc_bootstrap() {
190190
.with_stderr_data(str![[r#"
191191
[COMPILING] foo v0.0.1 ([ROOT]/foo)
192192
[WARNING] [email protected]: Cannot set `RUSTC_BOOTSTRAP=1` from build script of `foo v0.0.1 ([ROOT]/foo)`.
193-
[NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.
193+
[NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.
194194
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
195195
196196
"#]])

tests/testsuite/cargo_features.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ fn stable_feature_warns() {
263263
p.cargo("check")
264264
.with_stderr_data(str![[r#"
265265
[WARNING] the cargo feature `test-dummy-stable` has been stabilized in the 1.0 release and is no longer necessary to be listed in the manifest
266-
See https://doc.rust-lang.org/cargo/ for more information about using this feature.
266+
See https://doc.rust-lang.org/cargo/ for more information about using this feature.
267267
[CHECKING] a v0.0.1 ([ROOT]/foo)
268268
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
269269
@@ -753,8 +753,8 @@ fn z_stabilized() {
753753
.masquerade_as_nightly_cargo(&["always_nightly"])
754754
.with_stderr_data(str![[r#"
755755
[WARNING] flag `-Z cache-messages` has been stabilized in the 1.40 release, and is no longer necessary
756-
Message caching is now always enabled.
757-
756+
Message caching is now always enabled.
757+
758758
[CHECKING] foo v0.0.1 ([ROOT]/foo)
759759
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
760760

tests/testsuite/cargo_init/path_contains_separator/stderr.term.svg

Lines changed: 2 additions & 2 deletions
Loading

tests/testsuite/docscrape.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -448,20 +448,20 @@ fn no_fail_bad_lib() {
448448
[CHECKING] foo v0.0.1 ([ROOT]/foo)
449449
[SCRAPING] foo v0.0.1 ([ROOT]/foo)
450450
[WARNING] failed to check lib in package `foo` as a prerequisite for scraping examples from: example "ex", example "ex2"
451-
Try running with `--verbose` to see the error message.
452-
If an example should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` definition in Cargo.toml
453451
[WARNING] `foo` (lib) generated 1 warning
454452
[WARNING] failed to scan example "ex" in package `foo` for example code usage
455-
Try running with `--verbose` to see the error message.
456-
If an example should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` definition in Cargo.toml
457453
[WARNING] `foo` (example "ex") generated 1 warning
458454
[WARNING] failed to scan example "ex2" in package `foo` for example code usage
459-
Try running with `--verbose` to see the error message.
460-
If an example should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` definition in Cargo.toml
461455
[WARNING] `foo` (example "ex2") generated 1 warning
462456
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
463457
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
464458
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
459+
Try running with `--verbose` to see the error message.
460+
If an example should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` definition in Cargo.toml
461+
Try running with `--verbose` to see the error message.
462+
If an example should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` definition in Cargo.toml
463+
Try running with `--verbose` to see the error message.
464+
If an example should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` definition in Cargo.toml
465465
466466
"#]].unordered())
467467
.run();
@@ -531,8 +531,8 @@ fn no_fail_bad_example() {
531531
[CHECKING] foo v0.0.1 ([ROOT]/foo)
532532
[SCRAPING] foo v0.0.1 ([ROOT]/foo)
533533
[WARNING] failed to scan example "ex1" in package `foo` for example code usage
534-
Try running with `--verbose` to see the error message.
535-
If an example should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` definition in Cargo.toml
534+
Try running with `--verbose` to see the error message.
535+
If an example should not be scanned, then consider adding `doc-scrape-examples = false` to its `[[example]]` definition in Cargo.toml
536536
[WARNING] `foo` (example "ex1") generated 1 warning
537537
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
538538
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -614,8 +614,8 @@ fn no_scrape_with_dev_deps() {
614614
.with_stderr_data(str![[r#"
615615
[LOCKING] 1 package to latest compatible version
616616
[WARNING] Rustdoc did not scrape the following examples because they require dev-dependencies: ex
617-
If you want Rustdoc to scrape these examples, then add `doc-scrape-examples = true`
618-
to the [[example]] target configuration of at least one example.
617+
If you want Rustdoc to scrape these examples, then add `doc-scrape-examples = true`
618+
to the [[example]] target configuration of at least one example.
619619
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
620620
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
621621
[GENERATED] [ROOT]/foo/target/doc/foo/index.html

0 commit comments

Comments
 (0)