Skip to content

Commit 6c0532b

Browse files
committed
fix(shell): Switch to annotate snippets for warnings
This is part of #15944
1 parent ed2f8ef commit 6c0532b

34 files changed

+410
-407
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/alt_registry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ fn publish_with_registry_dependency() {
350350
.with_stderr_data(str![[r#"
351351
[UPDATING] `alternative` index
352352
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
353-
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
353+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
354354
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
355355
[UPDATING] `alternative` index
356356
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
@@ -517,7 +517,7 @@ fn publish_to_alt_registry() {
517517
.with_stderr_data(str![[r#"
518518
[UPDATING] `alternative` index
519519
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
520-
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
520+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
521521
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
522522
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
523523
[VERIFYING] foo v0.0.1 ([ROOT]/foo)
@@ -595,7 +595,7 @@ fn publish_with_crates_io_dep() {
595595
.with_stderr_data(str![[r#"
596596
[UPDATING] `alternative` index
597597
[WARNING] manifest has no documentation, homepage or repository.
598-
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
598+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
599599
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
600600
[UPDATING] `dummy-registry` index
601601
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)

tests/testsuite/bad_config.rs

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ fn dev_dependencies2() {
839839
.build();
840840
p.cargo("check").with_stderr_data(str![[r#"
841841
[WARNING] `dev_dependencies` is deprecated in favor of `dev-dependencies` and will not work in the 2024 edition
842-
(in the `foo` package)
842+
(in the `foo` package)
843843
[LOCKING] 1 package to latest compatible version
844844
[CHECKING] foo v0.1.0 ([ROOT]/foo)
845845
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -954,7 +954,7 @@ fn build_dependencies2() {
954954
.build();
955955
p.cargo("check").with_stderr_data(str![[r#"
956956
[WARNING] `build_dependencies` is deprecated in favor of `build-dependencies` and will not work in the 2024 edition
957-
(in the `foo` package)
957+
(in the `foo` package)
958958
[LOCKING] 1 package to latest compatible version
959959
[CHECKING] foo v0.1.0 ([ROOT]/foo)
960960
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -1062,7 +1062,7 @@ fn lib_crate_type2() {
10621062
p.cargo("check")
10631063
.with_stderr_data(str![[r#"
10641064
[WARNING] `crate_type` is deprecated in favor of `crate-type` and will not work in the 2024 edition
1065-
(in the `foo` library target)
1065+
(in the `foo` library target)
10661066
[CHECKING] foo v0.5.0 ([ROOT]/foo)
10671067
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
10681068
@@ -1153,7 +1153,7 @@ fn bin_crate_type2() {
11531153
p.cargo("check")
11541154
.with_stderr_data(str![[r#"
11551155
[WARNING] `crate_type` is deprecated in favor of `crate-type` and will not work in the 2024 edition
1156-
(in the `foo` binary target)
1156+
(in the `foo` binary target)
11571157
[CHECKING] foo v0.5.0 ([ROOT]/foo)
11581158
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
11591159
@@ -1262,9 +1262,9 @@ fn examples_crate_type2() {
12621262
p.cargo("check")
12631263
.with_stderr_data(str![[r#"
12641264
[WARNING] `crate_type` is deprecated in favor of `crate-type` and will not work in the 2024 edition
1265-
(in the `ex` example target)
1265+
(in the `ex` example target)
12661266
[WARNING] `crate_type` is deprecated in favor of `crate-type` and will not work in the 2024 edition
1267-
(in the `goodbye` example target)
1267+
(in the `goodbye` example target)
12681268
[CHECKING] foo v0.5.0 ([ROOT]/foo)
12691269
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
12701270
@@ -1401,7 +1401,7 @@ fn cargo_platform_build_dependencies2() {
14011401
p.cargo("check")
14021402
.with_stderr_data(str![[r#"
14031403
[WARNING] `build_dependencies` is deprecated in favor of `build-dependencies` and will not work in the 2024 edition
1404-
(in the `[HOST_TARGET]` platform target)
1404+
(in the `[HOST_TARGET]` platform target)
14051405
[LOCKING] 1 package to latest compatible version
14061406
[COMPILING] build v0.5.0 ([ROOT]/foo/build)
14071407
[COMPILING] foo v0.5.0 ([ROOT]/foo)
@@ -1532,7 +1532,7 @@ fn cargo_platform_dev_dependencies2() {
15321532
p.cargo("check")
15331533
.with_stderr_data(str![[r#"
15341534
[WARNING] `dev_dependencies` is deprecated in favor of `dev-dependencies` and will not work in the 2024 edition
1535-
(in the `[HOST_TARGET]` platform target)
1535+
(in the `[HOST_TARGET]` platform target)
15361536
[LOCKING] 1 package to latest compatible version
15371537
[CHECKING] foo v0.5.0 ([ROOT]/foo)
15381538
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -1661,7 +1661,7 @@ fn default_features2() {
16611661

16621662
p.cargo("check").with_stderr_data(str![[r#"
16631663
[WARNING] `default_features` is deprecated in favor of `default-features` and will not work in the 2024 edition
1664-
(in the `a` dependency)
1664+
(in the `a` dependency)
16651665
[LOCKING] 1 package to latest compatible version
16661666
[CHECKING] a v0.1.0 ([ROOT]/foo/a)
16671667
[CHECKING] foo v0.1.0 ([ROOT]/foo)
@@ -1836,7 +1836,7 @@ fn workspace_default_features2() {
18361836
[CHECKING] workspace_only v0.1.0 ([ROOT]/foo/workspace_only)
18371837
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
18381838
[WARNING] [ROOT]/foo/workspace_only/Cargo.toml: `default_features` is deprecated in favor of `default-features` and will not work in the 2024 edition
1839-
(in the `dep_workspace_only` dependency)
1839+
(in the `dep_workspace_only` dependency)
18401840
18411841
"#]]
18421842
.unordered(),
@@ -1947,7 +1947,7 @@ fn lib_proc_macro2() {
19471947
foo.cargo("check")
19481948
.with_stderr_data(str![[r#"
19491949
[WARNING] `proc_macro` is deprecated in favor of `proc-macro` and will not work in the 2024 edition
1950-
(in the `foo` library target)
1950+
(in the `foo` library target)
19511951
[CHECKING] foo v0.1.0 ([ROOT]/foo)
19521952
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
19531953
@@ -2035,7 +2035,7 @@ fn bin_proc_macro2() {
20352035
foo.cargo("check")
20362036
.with_stderr_data(str![[r#"
20372037
[WARNING] `proc_macro` is deprecated in favor of `proc-macro` and will not work in the 2024 edition
2038-
(in the `foo` binary target)
2038+
(in the `foo` binary target)
20392039
[CHECKING] foo v0.5.0 ([ROOT]/foo)
20402040
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
20412041
@@ -3473,22 +3473,22 @@ fn legacy_binary_paths_warnings() {
34733473
p.cargo("check -v")
34743474
.with_stderr_data(str![[r#"
34753475
[WARNING] An explicit [[bin]] section is specified in Cargo.toml which currently
3476-
disables Cargo from automatically inferring other binary targets.
3477-
This inference behavior will change in the Rust 2018 edition and the following
3478-
files will be included as a binary target:
3479-
3480-
* src/main.rs
3481-
3482-
This is likely to break cargo build or cargo test as these files may not be
3483-
ready to be compiled as a binary target today. You can future-proof yourself
3484-
and disable this warning by adding `autobins = false` to your [package]
3485-
section. You may also move the files to a location where Cargo would not
3486-
automatically infer them to be a target, such as in subfolders.
3487-
3488-
For more information on this warning you can consult
3489-
https://github.com/rust-lang/cargo/issues/5330
3476+
disables Cargo from automatically inferring other binary targets.
3477+
This inference behavior will change in the Rust 2018 edition and the following
3478+
files will be included as a binary target:
3479+
3480+
* src/main.rs
3481+
3482+
This is likely to break cargo build or cargo test as these files may not be
3483+
ready to be compiled as a binary target today. You can future-proof yourself
3484+
and disable this warning by adding `autobins = false` to your [package]
3485+
section. You may also move the files to a location where Cargo would not
3486+
automatically infer them to be a target, such as in subfolders.
3487+
3488+
For more information on this warning you can consult
3489+
https://github.com/rust-lang/cargo/issues/5330
34903490
[WARNING] path `src/main.rs` was erroneously implicitly accepted for binary `bar`,
3491-
please set bin.path in Cargo.toml
3491+
please set bin.path in Cargo.toml
34923492
[CHECKING] foo v1.0.0 ([ROOT]/foo)
34933493
[RUNNING] `rustc [..]`
34943494
[RUNNING] `rustc [..]`
@@ -3518,22 +3518,22 @@ please set bin.path in Cargo.toml
35183518
p.cargo("check -v")
35193519
.with_stderr_data(str![[r#"
35203520
[WARNING] An explicit [[bin]] section is specified in Cargo.toml which currently
3521-
disables Cargo from automatically inferring other binary targets.
3522-
This inference behavior will change in the Rust 2018 edition and the following
3523-
files will be included as a binary target:
3524-
3525-
* src/bin/main.rs
3526-
3527-
This is likely to break cargo build or cargo test as these files may not be
3528-
ready to be compiled as a binary target today. You can future-proof yourself
3529-
and disable this warning by adding `autobins = false` to your [package]
3530-
section. You may also move the files to a location where Cargo would not
3531-
automatically infer them to be a target, such as in subfolders.
3532-
3533-
For more information on this warning you can consult
3534-
https://github.com/rust-lang/cargo/issues/5330
3521+
disables Cargo from automatically inferring other binary targets.
3522+
This inference behavior will change in the Rust 2018 edition and the following
3523+
files will be included as a binary target:
3524+
3525+
* src/bin/main.rs
3526+
3527+
This is likely to break cargo build or cargo test as these files may not be
3528+
ready to be compiled as a binary target today. You can future-proof yourself
3529+
and disable this warning by adding `autobins = false` to your [package]
3530+
section. You may also move the files to a location where Cargo would not
3531+
automatically infer them to be a target, such as in subfolders.
3532+
3533+
For more information on this warning you can consult
3534+
https://github.com/rust-lang/cargo/issues/5330
35353535
[WARNING] path `src/bin/main.rs` was erroneously implicitly accepted for binary `bar`,
3536-
please set bin.path in Cargo.toml
3536+
please set bin.path in Cargo.toml
35373537
[CHECKING] foo v1.0.0 ([ROOT]/foo)
35383538
[RUNNING] `rustc [..]`
35393539
[RUNNING] `rustc [..]`
@@ -3562,7 +3562,7 @@ please set bin.path in Cargo.toml
35623562
p.cargo("check -v")
35633563
.with_stderr_data(str![[r#"
35643564
[WARNING] path `src/bar.rs` was erroneously implicitly accepted for binary `bar`,
3565-
please set bin.path in Cargo.toml
3565+
please set bin.path in Cargo.toml
35663566
[CHECKING] foo v1.0.0 ([ROOT]/foo)
35673567
[RUNNING] `rustc [..]`
35683568
[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] has-dashes@0.0.1: 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] has-dashes@0.0.1: 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] foo@0.0.1: 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/build_script_extra_link_arg.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ fn cdylib_link_arg_transitive() {
222222
[RUNNING] `[ROOT]/foo/target/debug/build/bar-[HASH]/build-script-build`
223223
[WARNING] bar@1.0.0: cargo::rustc-link-arg-cdylib was specified in the build script of bar v1.0.0 \
224224
([ROOT]/foo/bar), but that package does not contain a cdylib target
225-
226-
Allowing this was an unintended change in the 1.50 release, and may become an error in \
227-
the future. For more information, see <https://github.com/rust-lang/cargo/issues/9562>.
225+
226+
Allowing this was an unintended change in the 1.50 release, and may become an error in \
227+
the future. For more information, see <https://github.com/rust-lang/cargo/issues/9562>.
228228
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]
229229
[COMPILING] foo v0.1.0 ([ROOT]/foo)
230230
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]-C link-arg=--bogus[..]`

tests/testsuite/cargo_alias_config.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ fn alias_shadowing_external_subcommand() {
191191
.env("PATH", &path)
192192
.with_stderr_data(str![[r#"
193193
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
194-
This was previously accepted but is being phased out; it will become a hard error in a future release.
195-
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.
194+
This was previously accepted but is being phased out; it will become a hard error in a future release.
195+
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.
196196
[COMPILING] foo v0.5.0 ([ROOT]/foo)
197197
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
198198
@@ -226,8 +226,8 @@ fn default_args_alias() {
226226
.with_status(101)
227227
.with_stderr_data(str![[r#"
228228
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
229-
This was previously accepted but is being phased out; it will become a hard error in a future release.
230-
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.
229+
This was previously accepted but is being phased out; it will become a hard error in a future release.
230+
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.
231231
[ERROR] alias echo has unresolvable recursive definition: echo -> echo
232232
233233
"#]])
@@ -238,8 +238,8 @@ For more information, see issue #10049 <https://github.com/rust-lang/cargo/issue
238238
.with_status(101)
239239
.with_stderr_data(str![[r#"
240240
[WARNING] user-defined alias `echo` is shadowing an external subcommand found at: `[ROOT]/cargo-echo/target/debug/cargo-echo[EXE]`
241-
This was previously accepted but is being phased out; it will become a hard error in a future release.
242-
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.
241+
This was previously accepted but is being phased out; it will become a hard error in a future release.
242+
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.
243243
[ERROR] alias test-1 has unresolvable recursive definition: test-1 -> echo -> echo
244244
245245
"#]])

0 commit comments

Comments
 (0)