Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use annotate_snippets::{AnnotationKind, Group, Level, Renderer, Snippet};
use annotate_snippets::{AnnotationKind, Level, Renderer, Snippet};

#[divan::bench]
fn simple() -> String {
Expand All @@ -24,8 +24,10 @@ fn simple() -> String {
_ => continue,
}
}"#;
let message = &[
Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")).element(
let message = &[Level::ERROR
.primary_title("mismatched types")
.id("E0308")
.element(
Snippet::source(source)
.line_start(51)
.path("src/format.rs")
Expand All @@ -39,8 +41,7 @@ fn simple() -> String {
.span(26..724)
.label("expected enum `std::option::Option`"),
),
),
];
)];

let renderer = Renderer::plain();
let rendered = renderer.render(message);
Expand Down Expand Up @@ -69,17 +70,16 @@ fn fold(bencher: divan::Bencher<'_, '_>, context: usize) {
(input, span)
})
.bench_values(|(input, span)| {
let message =
&[
Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308"))
.element(
Snippet::source(&input).path("src/format.rs").annotation(
AnnotationKind::Context
.span(span)
.label("expected `Option<String>` because of return type"),
),
),
];
let message = &[Level::ERROR
.primary_title("mismatched types")
.id("E0308")
.element(
Snippet::source(&input).path("src/format.rs").annotation(
AnnotationKind::Context
.span(span)
.label("expected `Option<String>` because of return type"),
),
)];

let renderer = Renderer::plain();
let rendered = renderer.render(message);
Expand Down
26 changes: 12 additions & 14 deletions examples/custom_error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use annotate_snippets::renderer::DecorStyle;
use annotate_snippets::{AnnotationKind, Group, Level, Renderer, Snippet};
use annotate_snippets::{AnnotationKind, Level, Renderer, Snippet};

fn main() {
let source = r#"//@ compile-flags: -Ztreat-err-as-bug
Expand All @@ -15,19 +15,17 @@ fn main() {
pub static C: u32 = 0 - 1;
//~^ ERROR could not evaluate static initializer
"#;
let report = &[Group::with_title(
Level::ERROR
.with_name(Some("error: internal compiler error"))
.primary_title("could not evaluate static initializer")
.id("E0080"),
)
.element(
Snippet::source(source).path("$DIR/err.rs").annotation(
AnnotationKind::Primary
.span(386..391)
.label("attempt to compute `0_u32 - 1_u32`, which would overflow"),
),
)];
let report = &[Level::ERROR
.with_name(Some("error: internal compiler error"))
.primary_title("could not evaluate static initializer")
.id("E0080")
.element(
Snippet::source(source).path("$DIR/err.rs").annotation(
AnnotationKind::Primary
.span(386..391)
.label("attempt to compute `0_u32 - 1_u32`, which would overflow"),
),
)];

let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
anstream::println!("{}", renderer.render(report));
Expand Down
21 changes: 9 additions & 12 deletions examples/custom_level.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use annotate_snippets::renderer::DecorStyle;
use annotate_snippets::{AnnotationKind, Group, Level, Patch, Renderer, Snippet};
use annotate_snippets::{AnnotationKind, Level, Patch, Renderer, Snippet};

fn main() {
let source = r#"// Regression test for issue #114529
Expand Down Expand Up @@ -29,13 +29,10 @@ fn main() {
}
}
"#;
let report =
&[
Group::with_title(
Level::ERROR
.primary_title("`break` with value from a `while` loop")
.id("E0571"),
)
let report = &[
Level::ERROR
.primary_title("`break` with value from a `while` loop")
.id("E0571")
.element(
Snippet::source(source)
.line_start(1)
Expand All @@ -51,16 +48,16 @@ fn main() {
.label("you can't `break` with a value in a `while` loop"),
),
),
Group::with_title(Level::HELP.with_name(Some("suggestion")).secondary_title(
"use `break` on its own without a value inside this `while` loop",
))
Level::HELP
.with_name(Some("suggestion"))
.secondary_title("use `break` on its own without a value inside this `while` loop")
.element(
Snippet::source(source)
.line_start(1)
.path("$DIR/issue-114529-illegal-break-with-value.rs")
.patch(Patch::new(483..581, "break")),
),
];
];

let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
anstream::println!("{}", renderer.render(report));
Expand Down
10 changes: 5 additions & 5 deletions examples/expected_type.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Group, Level, Renderer, Snippet};
use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Level, Renderer, Snippet};

fn main() {
let source = r#" annotations: vec![SourceAnnotation {
label: "expected struct `annotate_snippets::snippet::Slice`, found reference"
,
range: <22, 25>,"#;
let report =
&[
Group::with_title(Level::ERROR.primary_title("expected type, found `22`")).element(
&[Level::ERROR
.primary_title("expected type, found `22`")
.element(
Snippet::source(source)
.line_start(26)
.path("examples/footer.rs")
Expand All @@ -19,8 +20,7 @@ fn main() {
.span(34..50)
.label("while parsing this struct"),
),
),
];
)];

let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
anstream::println!("{}", renderer.render(report));
Expand Down
16 changes: 9 additions & 7 deletions examples/footer.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Group, Level, Renderer, Snippet};

fn main() {
let report =
&[
Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")).element(
let report = &[
Level::ERROR
.primary_title("mismatched types")
.id("E0308")
.element(
Snippet::source(" slices: vec![\"A\",")
.line_start(13)
.path("src/multislice.rs")
.annotation(AnnotationKind::Primary.span(21..24).label(
"expected struct `annotate_snippets::snippet::Slice`, found reference",
)),
),
Group::with_title(Level::NOTE.secondary_title(
"expected type: `snippet::Annotation`\n found type: `__&__snippet::Annotation`",
)),
];
Group::with_title(Level::NOTE.secondary_title(
"expected type: `snippet::Annotation`\n found type: `__&__snippet::Annotation`",
)),
];

let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
anstream::println!("{}", renderer.render(report));
Expand Down
11 changes: 6 additions & 5 deletions examples/format.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Group, Level, Renderer, Snippet};
use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Level, Renderer, Snippet};

fn main() {
let source = r#") -> Option<String> {
Expand All @@ -23,8 +23,10 @@ fn main() {
_ => continue,
}
}"#;
let report = &[
Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308")).element(
let report = &[Level::ERROR
.primary_title("mismatched types")
.id("E0308")
.element(
Snippet::source(source)
.line_start(51)
.path("src/format.rs")
Expand All @@ -39,8 +41,7 @@ fn main() {
.span(26..724)
.label("expected enum `std::option::Option`"),
),
),
];
)];

let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
anstream::println!("{}", renderer.render(report));
Expand Down
20 changes: 12 additions & 8 deletions examples/highlight_message.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Group, Level, Renderer, Snippet};
use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Level, Renderer, Snippet};
use anstyle::AnsiColor;
use anstyle::Effects;
use anstyle::Style;
Expand Down Expand Up @@ -34,7 +34,9 @@ fn main() {
);

let report = &[
Group::with_title(Level::ERROR.primary_title("mismatched types").id("E0308"))
Level::ERROR
.primary_title("mismatched types")
.id("E0308")
.element(
Snippet::source(source)
.path("$DIR/highlighting.rs")
Expand All @@ -50,12 +52,14 @@ fn main() {
),
)
.element(Level::NOTE.message(&message)),
Group::with_title(Level::NOTE.secondary_title("function defined here")).element(
Snippet::source(source)
.path("$DIR/highlighting.rs")
.annotation(AnnotationKind::Context.span(200..333).label(""))
.annotation(AnnotationKind::Primary.span(194..199)),
),
Level::NOTE
.secondary_title("function defined here")
.element(
Snippet::source(source)
.path("$DIR/highlighting.rs")
.annotation(AnnotationKind::Context.span(200..333).label(""))
.annotation(AnnotationKind::Primary.span(194..199)),
),
];

let renderer = Renderer::styled()
Expand Down
6 changes: 3 additions & 3 deletions examples/highlight_source.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Group, Level, Renderer, Snippet};
use annotate_snippets::{renderer::DecorStyle, AnnotationKind, Level, Renderer, Snippet};

fn main() {
let source = r#"//@ compile-flags: -Z teach
Expand All @@ -9,8 +9,8 @@ const CON: Vec<i32> = vec![1, 2, 3]; //~ ERROR E0010
//~| ERROR cannot call non-const method
fn main() {}
"#;
let report = &[Group::with_title(Level::ERROR.primary_title("allocations are not allowed in constants")
.id("E0010"))
let report = &[Level::ERROR.primary_title("allocations are not allowed in constants")
.id("E0010")
.element(
Snippet::source(source)
.path("$DIR/E0010-teach.rs")
Expand Down
42 changes: 20 additions & 22 deletions examples/id_hyperlink.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
use annotate_snippets::renderer::DecorStyle;
use annotate_snippets::{AnnotationKind, Group, Level, Renderer, Snippet};
use annotate_snippets::{AnnotationKind, Level, Renderer, Snippet};

fn main() {
let source = r#"//@ compile-flags: -Zterminal-urls=yes
fn main() {
let () = 4; //~ ERROR
}
"#;
let report = &[Group::with_title(
Level::ERROR
.primary_title("mismatched types")
.id("E0308")
.id_url("https://doc.rust-lang.org/error_codes/E0308.html"),
)
.element(
Snippet::source(source)
.line_start(1)
.path("$DIR/terminal_urls.rs")
.annotation(
AnnotationKind::Primary
.span(59..61)
.label("expected integer, found `()`"),
)
.annotation(
AnnotationKind::Context
.span(64..65)
.label("this expression has type `{integer}`"),
),
)];
let report = &[Level::ERROR
.primary_title("mismatched types")
.id("E0308")
.id_url("https://doc.rust-lang.org/error_codes/E0308.html")
.element(
Snippet::source(source)
.line_start(1)
.path("$DIR/terminal_urls.rs")
.annotation(
AnnotationKind::Primary
.span(59..61)
.label("expected integer, found `()`"),
)
.annotation(
AnnotationKind::Context
.span(64..65)
.label("this expression has type `{integer}`"),
),
)];

let renderer = Renderer::styled().decor_style(DecorStyle::Unicode);
anstream::println!("{}", renderer.render(report));
Expand Down
Loading
Loading