Skip to content

Commit d36c326

Browse files
committed
chore(deps): update rust crate annotate-snippets to 0.12.1
1 parent 96aec67 commit d36c326

29 files changed

+118
-170
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ homepage = "https://github.com/rust-lang/cargo"
1818
repository = "https://github.com/rust-lang/cargo"
1919

2020
[workspace.dependencies]
21-
annotate-snippets = "0.11.5"
21+
annotate-snippets = { version = "0.12.1", features = ["simd"] }
2222
anstream = "0.6.20"
2323
anstyle = "1.0.11"
2424
anyhow = "1.0.98"

src/cargo/core/shell.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22
use std::io::IsTerminal;
33
use std::io::prelude::*;
44

5-
use annotate_snippets::{Message, Renderer};
5+
use annotate_snippets::{Renderer, Report};
66
use anstream::AutoStream;
77
use anstyle::Style;
88

@@ -406,16 +406,16 @@ impl Shell {
406406
Ok(())
407407
}
408408

409-
/// Prints the passed in [Message] to stderr
410-
pub fn print_message(&mut self, message: Message<'_>) -> std::io::Result<()> {
409+
/// Prints the passed in [`Report`] to stderr
410+
pub fn print_report(&mut self, report: Report<'_>) -> std::io::Result<()> {
411411
let term_width = self
412412
.err_width()
413413
.diagnostic_terminal_width()
414414
.unwrap_or(annotate_snippets::renderer::DEFAULT_TERM_WIDTH);
415415
writeln!(
416416
self.err(),
417417
"{}",
418-
Renderer::styled().term_width(term_width).render(message)
418+
Renderer::styled().term_width(term_width).render(report)
419419
)
420420
}
421421
}

src/cargo/util/lints.rs

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::core::{Edition, Feature, Features, Manifest, Package};
22
use crate::{CargoResult, GlobalContext};
3-
use annotate_snippets::{Level, Snippet};
3+
use annotate_snippets::{AnnotationKind, Group, Level, Snippet};
44
use cargo_util_schemas::manifest::{TomlLintLevel, TomlToolLints};
55
use pathdiff::diff_paths;
66
use std::fmt::Display;
@@ -145,32 +145,33 @@ fn verify_feature_enabled(
145145
panic!("could not find `cargo::{lint_name}` in `[lints]`, or `[workspace.lints]` ")
146146
};
147147

148-
let mut message = Level::Error
149-
.title(&title)
150-
.snippet(
151-
Snippet::source(contents)
152-
.origin(path)
153-
.annotation(Level::Error.span(span.key).label(&label))
154-
.fold(true),
155-
)
156-
.footer(Level::Help.title(&help));
148+
let mut report = Vec::new();
149+
report.push(
150+
Group::with_title(Level::ERROR.primary_title(title))
151+
.element(
152+
Snippet::source(contents)
153+
.path(path)
154+
.annotation(AnnotationKind::Primary.span(span.key).label(label)),
155+
)
156+
.element(Level::HELP.message(help)),
157+
);
157158

158159
if let Some(inherit_span) = get_key_value_span(manifest.document(), &["lints", "workspace"])
159160
{
160-
message = message.footer(
161-
Level::Note.title(&second_title).snippet(
161+
report.push(
162+
Group::with_title(Level::NOTE.secondary_title(second_title)).element(
162163
Snippet::source(manifest.contents())
163-
.origin(&manifest_path)
164+
.path(manifest_path)
164165
.annotation(
165-
Level::Note.span(inherit_span.key.start..inherit_span.value.end),
166-
)
167-
.fold(true),
166+
AnnotationKind::Context
167+
.span(inherit_span.key.start..inherit_span.value.end),
168+
),
168169
),
169170
);
170171
}
171172

172173
*error_count += 1;
173-
gctx.shell().print_message(message)?;
174+
gctx.shell().print_report(&report)?;
174175
}
175176
Ok(())
176177
}
@@ -330,12 +331,12 @@ impl LintLevel {
330331
self == &LintLevel::Forbid || self == &LintLevel::Deny
331332
}
332333

333-
pub fn to_diagnostic_level(self) -> Level {
334+
pub fn to_diagnostic_level(self) -> Level<'static> {
334335
match self {
335336
LintLevel::Allow => unreachable!("allow does not map to a diagnostic level"),
336-
LintLevel::Warn => Level::Warning,
337-
LintLevel::Deny => Level::Error,
338-
LintLevel::Forbid => Level::Error,
337+
LintLevel::Warn => Level::WARNING,
338+
LintLevel::Deny => Level::ERROR,
339+
LintLevel::Forbid => Level::ERROR,
339340
}
340341
}
341342
}
@@ -450,17 +451,15 @@ pub fn check_im_a_teapot(
450451

451452
let span = get_key_value_span(manifest.document(), &["package", "im-a-teapot"]).unwrap();
452453

453-
let message = level
454-
.title(IM_A_TEAPOT.desc)
455-
.snippet(
454+
let report = &[Group::with_title(level.primary_title(IM_A_TEAPOT.desc))
455+
.element(
456456
Snippet::source(manifest.contents())
457-
.origin(&manifest_path)
458-
.annotation(level.span(span.key.start..span.value.end))
459-
.fold(true),
457+
.path(&manifest_path)
458+
.annotation(AnnotationKind::Primary.span(span.key.start..span.value.end)),
460459
)
461-
.footer(Level::Note.title(&emitted_reason));
460+
.element(Level::NOTE.message(&emitted_reason))];
462461

463-
gctx.shell().print_message(message)?;
462+
gctx.shell().print_report(report)?;
464463
}
465464
Ok(())
466465
}
@@ -540,37 +539,36 @@ fn output_unknown_lints(
540539
panic!("could not find `cargo::{lint_name}` in `[lints]`, or `[workspace.lints]` ")
541540
};
542541

543-
let mut message = level.title(&title).snippet(
542+
let mut report = Vec::new();
543+
let mut group = Group::with_title(level.clone().primary_title(title)).element(
544544
Snippet::source(contents)
545-
.origin(path)
546-
.annotation(Level::Error.span(span.key))
547-
.fold(true),
545+
.path(path)
546+
.annotation(AnnotationKind::Primary.span(span.key)),
548547
);
549-
550548
if emitted_source.is_none() {
551549
emitted_source = Some(UNKNOWN_LINTS.emitted_source(lint_level, reason));
552-
message = message.footer(Level::Note.title(emitted_source.as_ref().unwrap()));
550+
group = group.element(Level::NOTE.message(emitted_source.as_ref().unwrap()));
553551
}
554-
555552
if let Some(help) = help.as_ref() {
556-
message = message.footer(Level::Help.title(help));
553+
group = group.element(Level::HELP.message(help));
557554
}
555+
report.push(group);
558556

559557
if let Some(inherit_span) = get_key_value_span(manifest.document(), &["lints", "workspace"])
560558
{
561-
message = message.footer(
562-
Level::Note.title(&second_title).snippet(
559+
report.push(
560+
Group::with_title(Level::NOTE.secondary_title(second_title)).element(
563561
Snippet::source(manifest.contents())
564-
.origin(&manifest_path)
562+
.path(manifest_path)
565563
.annotation(
566-
Level::Note.span(inherit_span.key.start..inherit_span.value.end),
567-
)
568-
.fold(true),
564+
AnnotationKind::Context
565+
.span(inherit_span.key.start..inherit_span.value.end),
566+
),
569567
),
570-
)
568+
);
571569
}
572570

573-
gctx.shell().print_message(message)?;
571+
gctx.shell().print_report(&report)?;
574572
}
575573

576574
Ok(())

src/cargo/util/toml/mod.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use annotate_snippets::{Level, Snippet};
1+
use annotate_snippets::{AnnotationKind, Group, Level, Snippet};
22
use std::borrow::Cow;
33
use std::collections::{BTreeMap, BTreeSet, HashMap};
44
use std::ffi::OsStr;
@@ -1879,12 +1879,11 @@ fn missing_dep_diagnostic(
18791879
"`{}` is an unused optional dependency since no feature enables it",
18801880
&dep_name
18811881
);
1882-
let message = Level::Error.title(&title);
1883-
let snippet = Snippet::source(&contents)
1884-
.origin(&manifest_path)
1885-
.fold(true)
1886-
.annotation(Level::Error.span(feature_span.value));
1887-
let message = if missing_dep.weak_optional {
1882+
let group = Group::with_title(Level::ERROR.primary_title(&title));
1883+
let snippet = Snippet::source(contents)
1884+
.path(manifest_path)
1885+
.annotation(AnnotationKind::Primary.span(feature_span.value));
1886+
let group = if missing_dep.weak_optional {
18881887
let mut orig_deps = vec![
18891888
(
18901889
orig_toml.dependencies.as_ref(),
@@ -1920,17 +1919,20 @@ fn missing_dep_diagnostic(
19201919
.collect::<Vec<_>>();
19211920
let dep_span = get_key_value_span(&document, &toml_path).unwrap();
19221921

1923-
message
1924-
.snippet(snippet.annotation(Level::Warning.span(dep_span.key).label(&info_label)))
1925-
.footer(Level::Help.title(&help))
1922+
group
1923+
.element(
1924+
snippet
1925+
.annotation(AnnotationKind::Context.span(dep_span.key).label(info_label)),
1926+
)
1927+
.element(Level::HELP.message(help))
19261928
} else {
1927-
message.snippet(snippet)
1929+
group.element(snippet)
19281930
}
19291931
} else {
1930-
message.snippet(snippet)
1932+
group.element(snippet)
19311933
};
19321934

1933-
if let Err(err) = gctx.shell().print_message(message) {
1935+
if let Err(err) = gctx.shell().print_report(&[group]) {
19341936
return Err(err.into());
19351937
}
19361938
Err(AlreadyPrintedError::new(anyhow!("").into()).into())
@@ -2792,13 +2794,13 @@ fn emit_diagnostic(
27922794
.unwrap_or_else(|| manifest_file.to_path_buf())
27932795
.display()
27942796
.to_string();
2795-
let message = Level::Error.title(e.message()).snippet(
2797+
let group = Group::with_title(Level::ERROR.primary_title(e.message())).element(
27962798
Snippet::source(contents)
2797-
.origin(&manifest_path)
2798-
.fold(true)
2799-
.annotation(Level::Error.span(span)),
2799+
.path(manifest_path)
2800+
.annotation(AnnotationKind::Primary.span(span)),
28002801
);
2801-
if let Err(err) = gctx.shell().print_message(message) {
2802+
2803+
if let Err(err) = gctx.shell().print_report(&[group]) {
28022804
return err.into();
28032805
}
28042806
return AlreadyPrintedError::new(e.into()).into();

tests/testsuite/alt_registry.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -749,13 +749,12 @@ fn bad_registry_name() {
749749
.with_status(101)
750750
.with_stderr_data(str![[r#"
751751
[ERROR] invalid character ` ` in registry name: `bad name`, characters must be Unicode XID characters (numbers, `-`, `_`, or most letters)
752-
753-
752+
753+
754754
--> Cargo.toml:8:17
755755
|
756756
8 | [dependencies.bar]
757757
| ^^^^^^^^^^^^^^^^^^
758-
|
759758
760759
"#]])
761760
.run();
@@ -1976,13 +1975,12 @@ fn empty_dependency_registry() {
19761975
.with_status(101)
19771976
.with_stderr_data(str![[r#"
19781977
[ERROR] registry name cannot be empty
1979-
1980-
1978+
1979+
19811980
--> Cargo.toml:8:23
19821981
|
19831982
8 | bar = { version = "0.1.0", registry = "" }
19841983
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1985-
|
19861984
19871985
"#]])
19881986
.run();

tests/testsuite/bad_config.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,12 @@ fn malformed_override() {
455455
.with_status(101)
456456
.with_stderr_data(str![[r#"
457457
[ERROR] newlines are unsupported in inline tables, expected nothing
458-
--> Cargo.toml:9:27
459-
|
460-
9 | native = {
461-
| ^
462-
|
458+
--> Cargo.toml:9:27
459+
|
460+
9 | native = {
461+
| ___________________________^
462+
10 | | foo: "bar"
463+
| |_^
463464
464465
"#]])
465466
.run();
@@ -2635,7 +2636,6 @@ fn bad_dependency() {
26352636
|
26362637
9 | bar = 3
26372638
| ^
2638-
|
26392639
26402640
"#]])
26412641
.run();
@@ -2664,13 +2664,12 @@ fn bad_dependency_true_literal() {
26642664
.with_status(101)
26652665
.with_stderr_data(str![[r#"
26662666
[ERROR] invalid type: boolean `true`, expected a version string like "0.9.8" or a detailed dependency like { version = "0.9.8" }
2667-
[NOTE] if you meant to use a workspace member, you can write
2668-
dep.workspace = true
2667+
[NOTE] if you meant to use a workspace member, you can write
2668+
dep.workspace = true
26692669
--> Cargo.toml:9:23
26702670
|
26712671
9 | bar = true
26722672
| ^^^^
2673-
|
26742673
26752674
"#]])
26762675
.run();
@@ -2703,7 +2702,6 @@ fn bad_debuginfo() {
27032702
|
27042703
9 | debug = 'a'
27052704
| ^^^
2706-
|
27072705
27082706
"#]])
27092707
.run();
@@ -2736,7 +2734,6 @@ fn bad_debuginfo2() {
27362734
|
27372735
9 | debug = 3.6
27382736
| ^^^
2739-
|
27402737
27412738
"#]])
27422739
.run();
@@ -2767,7 +2764,6 @@ fn bad_opt_level() {
27672764
|
27682765
7 | build = 3
27692766
| ^
2770-
|
27712767
27722768
"#]])
27732769
.run();
@@ -3067,7 +3063,6 @@ fn bad_trim_paths() {
30673063
|
30683064
8 | trim-paths = "split-debuginfo"
30693065
| ^^^^^^^^^^^^^^^^^
3070-
|
30713066
30723067
"#]])
30733068
.run();

0 commit comments

Comments
 (0)