Skip to content

Commit f1be881

Browse files
committed
fix(shell): Switch to annotate snippets for error
1 parent a43a4d0 commit f1be881

File tree

133 files changed

+1407
-1409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+1407
-1409
lines changed

src/cargo/core/shell.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,10 @@ impl Shell {
213213

214214
/// Prints a red 'error' message.
215215
pub fn error<T: fmt::Display>(&mut self, message: T) -> CargoResult<()> {
216-
if self.needs_clear {
217-
self.err_erase_line();
218-
}
219-
self.output
220-
.message_stderr(&"error", Some(&message), &ERROR, false)
216+
let report = &[annotate_snippets::Group::with_title(
217+
annotate_snippets::Level::ERROR.secondary_title(message.to_string()),
218+
)];
219+
self.print_report(report, true)
221220
}
222221

223222
/// Prints an amber 'warning' message.

tests/testsuite/alt_registry.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ fn block_publish_due_to_no_token() {
469469
.with_stderr_data(str![[r#"
470470
[UPDATING] `alternative` index
471471
[ERROR] no token found for `alternative`, please run `cargo login --registry alternative`
472-
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
472+
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
473473
474474
"#]])
475475
.run();
@@ -496,7 +496,7 @@ fn cargo_registries_crates_io_protocol() {
496496
.with_stderr_data(str![[r#"
497497
[UPDATING] `alternative` index
498498
[ERROR] no token found for `alternative`, please run `cargo login --registry alternative`
499-
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
499+
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
500500
501501
"#]])
502502
.run();
@@ -1885,7 +1885,7 @@ fn warn_for_unused_fields() {
18851885
[UPDATING] `alternative` index
18861886
[WARNING] unused config key `registries.alternative.unexpected-field` in `[ROOT]/foo/.cargo/config.toml`
18871887
[ERROR] no token found for `alternative`, please run `cargo login --registry alternative`
1888-
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
1888+
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
18891889
18901890
"#]])
18911891
.run();
@@ -1900,7 +1900,7 @@ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
19001900
[UPDATING] crates.io index
19011901
[WARNING] unused config key `registry.unexpected-field` in `[ROOT]/foo/.cargo/config.toml`
19021902
[ERROR] no token found, please run `cargo login`
1903-
or use environment variable CARGO_REGISTRY_TOKEN
1903+
or use environment variable CARGO_REGISTRY_TOKEN
19041904
19051905
"#]])
19061906
.run();

tests/testsuite/artifact_dep.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3305,7 +3305,7 @@ fn check_transitive_artifact_dependency_with_different_target() {
33053305
.with_stderr_data(str![[r#"
33063306
[LOCKING] 2 packages to latest compatible versions
33073307
[ERROR] failed to determine target information for target `custom-target`.
3308-
Artifact dependency `baz` in package `bar v0.0.0 ([ROOT]/foo/bar)` requires building for `custom-target`
3308+
Artifact dependency `baz` in package `bar v0.0.0 ([ROOT]/foo/bar)` requires building for `custom-target`
33093309
33103310
Caused by:
33113311
failed to run `rustc` to learn about target-specific information

tests/testsuite/bad_config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,7 @@ fn workspace_default_features2_2024() {
19171917
.with_status(101)
19181918
.with_stderr_data(str![[r#"
19191919
[ERROR] failed to load manifest for workspace member `[ROOT]/foo/workspace_only`
1920-
referenced by workspace at `[ROOT]/foo/Cargo.toml`
1920+
referenced by workspace at `[ROOT]/foo/Cargo.toml`
19211921
19221922
Caused by:
19231923
failed to parse manifest at `[ROOT]/foo/workspace_only/Cargo.toml`
@@ -3009,7 +3009,7 @@ fn redefined_sources() {
30093009
.with_status(101)
30103010
.with_stderr_data(str![[r#"
30113011
[ERROR] source `foo` defines source registry `crates-io`, but that source is already defined by `crates-io`
3012-
[NOTE] Sources are not allowed to be defined multiple times.
3012+
[NOTE] Sources are not allowed to be defined multiple times.
30133013
30143014
"#]])
30153015
.run();
@@ -3030,7 +3030,7 @@ fn redefined_sources() {
30303030
.with_status(101)
30313031
.with_stderr_data(str![[r#"
30323032
[ERROR] source `[..]` defines source dir [ROOT]/foo/index, but that source is already defined by `[..]`
3033-
[NOTE] Sources are not allowed to be defined multiple times.
3033+
[NOTE] Sources are not allowed to be defined multiple times.
30343034
30353035
"#]])
30363036
.run();

tests/testsuite/bench.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,8 +1443,8 @@ fn test_bench_no_fail_fast() {
14431443
[RUNNING] benches/b1.rs (target/release/deps/b1-[HASH][EXE])
14441444
[ERROR] bench failed, to rerun pass `--bench b1`
14451445
[ERROR] 2 targets failed:
1446-
`--bin foo`
1447-
`--bench b1`
1446+
`--bin foo`
1447+
`--bench b1`
14481448
14491449
"#]])
14501450
.with_stdout_data(

tests/testsuite/build.rs

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,8 +1278,8 @@ fn cargo_compile_with_dep_name_mismatch() {
12781278
.with_status(101)
12791279
.with_stderr_data(str![[r#"
12801280
[ERROR] no matching package named `notquitebar` found
1281-
location searched: [ROOT]/foo/bar
1282-
required by package `foo v0.0.1 ([ROOT]/foo)`
1281+
location searched: [ROOT]/foo/bar
1282+
required by package `foo v0.0.1 ([ROOT]/foo)`
12831283
12841284
"#]])
12851285
.run();
@@ -1335,8 +1335,8 @@ fn cargo_compile_with_filename() {
13351335
.with_status(101)
13361336
.with_stderr_data(str![[r#"
13371337
[ERROR] no bin target named `bin.rs` in default-run packages
1338-
[HELP] available bin targets:
1339-
a
1338+
[HELP] available bin targets:
1339+
a
13401340
13411341
"#]])
13421342
.run();
@@ -1345,8 +1345,8 @@ fn cargo_compile_with_filename() {
13451345
.with_status(101)
13461346
.with_stderr_data(str![[r#"
13471347
[ERROR] no bin target named `a.rs` in default-run packages
1348-
1349-
[HELP] a target with a similar name exists: `a`
1348+
1349+
[HELP] a target with a similar name exists: `a`
13501350
13511351
"#]])
13521352
.run();
@@ -1355,8 +1355,8 @@ fn cargo_compile_with_filename() {
13551355
.with_status(101)
13561356
.with_stderr_data(str![[r#"
13571357
[ERROR] no example target named `example.rs` in default-run packages
1358-
[HELP] available example targets:
1359-
a
1358+
[HELP] available example targets:
1359+
a
13601360
13611361
"#]])
13621362
.run();
@@ -1365,8 +1365,8 @@ fn cargo_compile_with_filename() {
13651365
.with_status(101)
13661366
.with_stderr_data(str![[r#"
13671367
[ERROR] no example target named `a.rs` in default-run packages
1368-
1369-
[HELP] a target with a similar name exists: `a`
1368+
1369+
[HELP] a target with a similar name exists: `a`
13701370
13711371
"#]])
13721372
.run();
@@ -1408,17 +1408,17 @@ fn incompatible_dependencies() {
14081408
.with_stderr_data(str![[r#"
14091409
[UPDATING] `dummy-registry` index
14101410
[ERROR] failed to select a version for `bad`.
1411-
... required by package `qux v0.1.0`
1412-
... which satisfies dependency `qux = "^0.1.0"` of package `foo v0.0.1 ([ROOT]/foo)`
1413-
versions that meet the requirements `>=1.0.1` are: 1.0.2, 1.0.1
1414-
1415-
all possible versions conflict with previously selected packages.
1416-
1417-
previously selected package `bad v1.0.0`
1418-
... which satisfies dependency `bad = "=1.0.0"` of package `baz v0.1.0`
1419-
... which satisfies dependency `baz = "^0.1.0"` of package `foo v0.0.1 ([ROOT]/foo)`
1420-
1421-
failed to select a version for `bad` which could resolve this conflict
1411+
... required by package `qux v0.1.0`
1412+
... which satisfies dependency `qux = "^0.1.0"` of package `foo v0.0.1 ([ROOT]/foo)`
1413+
versions that meet the requirements `>=1.0.1` are: 1.0.2, 1.0.1
1414+
1415+
all possible versions conflict with previously selected packages.
1416+
1417+
previously selected package `bad v1.0.0`
1418+
... which satisfies dependency `bad = "=1.0.0"` of package `baz v0.1.0`
1419+
... which satisfies dependency `baz = "^0.1.0"` of package `foo v0.0.1 ([ROOT]/foo)`
1420+
1421+
failed to select a version for `bad` which could resolve this conflict
14221422
14231423
"#]])
14241424
.run();
@@ -1456,20 +1456,20 @@ fn incompatible_dependencies_with_multi_semver() {
14561456
.with_stderr_data(str![[r#"
14571457
[UPDATING] `dummy-registry` index
14581458
[ERROR] failed to select a version for `bad`.
1459-
... required by package `foo v0.0.1 ([ROOT]/foo)`
1460-
versions that meet the requirements `>=1.0.1, <=2.0.0` are: 2.0.0, 1.0.1
1461-
1462-
all possible versions conflict with previously selected packages.
1463-
1464-
previously selected package `bad v2.0.1`
1465-
... which satisfies dependency `bad = ">=2.0.1"` of package `baz v0.1.0`
1466-
... which satisfies dependency `baz = "^0.1.0"` of package `foo v0.0.1 ([ROOT]/foo)`
1467-
1468-
previously selected package `bad v1.0.0`
1469-
... which satisfies dependency `bad = "=1.0.0"` of package `bar v0.1.0`
1470-
... which satisfies dependency `bar = "^0.1.0"` of package `foo v0.0.1 ([ROOT]/foo)`
1471-
1472-
failed to select a version for `bad` which could resolve this conflict
1459+
... required by package `foo v0.0.1 ([ROOT]/foo)`
1460+
versions that meet the requirements `>=1.0.1, <=2.0.0` are: 2.0.0, 1.0.1
1461+
1462+
all possible versions conflict with previously selected packages.
1463+
1464+
previously selected package `bad v2.0.1`
1465+
... which satisfies dependency `bad = ">=2.0.1"` of package `baz v0.1.0`
1466+
... which satisfies dependency `baz = "^0.1.0"` of package `foo v0.0.1 ([ROOT]/foo)`
1467+
1468+
previously selected package `bad v1.0.0`
1469+
... which satisfies dependency `bad = "=1.0.0"` of package `bar v0.1.0`
1470+
... which satisfies dependency `bar = "^0.1.0"` of package `foo v0.0.1 ([ROOT]/foo)`
1471+
1472+
failed to select a version for `bad` which could resolve this conflict
14731473
14741474
"#]])
14751475
.run();
@@ -2093,8 +2093,8 @@ fn self_dependency() {
20932093
.with_status(101)
20942094
.with_stderr_data(str![[r#"
20952095
[ERROR] cyclic package dependency: package `test v0.0.0 ([ROOT]/foo)` depends on itself. Cycle:
2096-
package `test v0.0.0 ([ROOT]/foo)`
2097-
... which satisfies path dependency `test` of package `test v0.0.0 ([ROOT]/foo)`
2096+
package `test v0.0.0 ([ROOT]/foo)`
2097+
... which satisfies path dependency `test` of package `test v0.0.0 ([ROOT]/foo)`
20982098
20992099
"#]])
21002100
.run();
@@ -3099,9 +3099,9 @@ fn cyclic_deps_rejected() {
30993099
.with_status(101)
31003100
.with_stderr_data(str![[r#"
31013101
[ERROR] cyclic package dependency: package `a v0.0.1 ([ROOT]/foo/a)` depends on itself. Cycle:
3102-
package `a v0.0.1 ([ROOT]/foo/a)`
3103-
... which satisfies path dependency `a` of package `foo v0.0.1 ([ROOT]/foo)`
3104-
... which satisfies path dependency `foo` of package `a v0.0.1 ([ROOT]/foo/a)`
3102+
package `a v0.0.1 ([ROOT]/foo/a)`
3103+
... which satisfies path dependency `a` of package `foo v0.0.1 ([ROOT]/foo)`
3104+
... which satisfies path dependency `foo` of package `a v0.0.1 ([ROOT]/foo/a)`
31053105
31063106
"#]])
31073107
.run();
@@ -5369,8 +5369,8 @@ fn avoid_dev_deps() {
53695369
.with_stderr_data(str![[r#"
53705370
[UPDATING] `dummy-registry` index
53715371
[ERROR] no matching package named `baz` found
5372-
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
5373-
required by package `bar v0.1.0 ([ROOT]/foo)`
5372+
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
5373+
required by package `bar v0.1.0 ([ROOT]/foo)`
53745374
53755375
"#]])
53765376
.run();
@@ -5491,8 +5491,8 @@ fn target_filters_workspace() {
54915491
.with_status(101)
54925492
.with_stderr_data(str![[r#"
54935493
[ERROR] no example target named `ex` in default-run packages
5494-
5495-
[HELP] a target with a similar name exists: `ex1`
5494+
5495+
[HELP] a target with a similar name exists: `ex1`
54965496
54975497
"#]])
54985498
.run();
@@ -5501,8 +5501,8 @@ fn target_filters_workspace() {
55015501
.with_status(101)
55025502
.with_stderr_data(str![[r#"
55035503
[ERROR] no example target matches pattern `ex??` in default-run packages
5504-
5505-
[HELP] a target with a similar name exists: `ex1`
5504+
5505+
[HELP] a target with a similar name exists: `ex1`
55065506
55075507
"#]])
55085508
.run();

tests/testsuite/build_dir.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ fn template_should_error_for_invalid_variables() {
479479
.with_status(101)
480480
.with_stderr_data(str![[r#"
481481
[ERROR] unexpected variable `fake` in build.build-dir path `{fake}/build-dir`
482-
483-
[HELP] available template variables are `{workspace-root}`, `{cargo-cache-home}`, `{workspace-path-hash}`
482+
483+
[HELP] available template variables are `{workspace-root}`, `{cargo-cache-home}`, `{workspace-path-hash}`
484484
485485
"#]])
486486
.run();
@@ -503,8 +503,8 @@ fn template_should_suggest_nearest_variable() {
503503
.with_status(101)
504504
.with_stderr_data(str![[r#"
505505
[ERROR] unexpected variable `workspace-ro` in build.build-dir path `{workspace-ro}/build-dir`
506-
507-
[HELP] a template variable with a similar name exists: `workspace-root`
506+
507+
[HELP] a template variable with a similar name exists: `workspace-root`
508508
509509
"#]])
510510
.run();

0 commit comments

Comments
 (0)