Skip to content

Remove message #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 27, 2025
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
16 changes: 8 additions & 8 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ fn simple() -> String {
_ => continue,
}
}"#;
let message = Level::ERROR.header("mismatched types").id("E0308").group(
Group::new().element(
let message = &[Group::new()
.element(Level::ERROR.title("mismatched types").id("E0308"))
.element(
Snippet::source(source)
.line_start(51)
.path("src/format.rs")
Expand All @@ -39,8 +40,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,8 +69,9 @@ fn fold(bencher: divan::Bencher<'_, '_>, context: usize) {
(input, span)
})
.bench_values(|(input, span)| {
let message = Level::ERROR.header("mismatched types").id("E0308").group(
Group::new().element(
let message = &[Group::new()
.element(Level::ERROR.title("mismatched types").id("E0308"))
.element(
Snippet::source(&input)
.fold(true)
.path("src/format.rs")
Expand All @@ -79,8 +80,7 @@ fn fold(bencher: divan::Bencher<'_, '_>, context: usize) {
.span(span)
.label("expected `Option<String>` because of return type"),
),
),
);
)];

let renderer = Renderer::plain();
let rendered = renderer.render(message);
Expand Down
33 changes: 17 additions & 16 deletions examples/custom_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@ fn main() {
pub static C: u32 = 0 - 1;
//~^ ERROR could not evaluate static initializer
"#;
let message = Level::ERROR
.text(Some("error: internal compiler error"))
.header("could not evaluate static initializer")
.id("E0080")
.group(
Group::new().element(
Snippet::source(source)
.path("$DIR/err.rs")
.fold(true)
.annotation(
AnnotationKind::Primary
.span(386..391)
.label("attempt to compute `0_u32 - 1_u32`, which would overflow"),
),
),
);
let message = &[Group::new()
.element(
Level::ERROR
.text(Some("error: internal compiler error"))
.title("could not evaluate static initializer")
.id("E0080"),
)
.element(
Snippet::source(source)
.path("$DIR/err.rs")
.fold(true)
.annotation(
AnnotationKind::Primary
.span(386..391)
.label("attempt to compute `0_u32 - 1_u32`, which would overflow"),
),
)];

let renderer = Renderer::styled().theme(OutputTheme::Unicode);
anstream::println!("{}", renderer.render(message));
Expand Down
43 changes: 22 additions & 21 deletions examples/custom_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ fn main() {
}
}
"#;
let message = Level::ERROR
.header("`break` with value from a `while` loop")
.id("E0571")
.group(
Group::new().element(
let message = &[
Group::new()
.element(
Level::ERROR
.title("`break` with value from a `while` loop")
.id("E0571"),
)
.element(
Snippet::source(source)
.line_start(1)
.path("$DIR/issue-114529-illegal-break-with-value.rs")
Expand All @@ -49,22 +52,20 @@ fn main() {
.label("you can't `break` with a value in a `while` loop"),
),
),
)
.group(
Group::new()
.element(
Level::HELP
.text(Some("suggestion"))
.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")
.fold(true)
.patch(Patch::new(483..581, "break")),
),
);
Group::new()
.element(
Level::HELP
.text(Some("suggestion"))
.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")
.fold(true)
.patch(Patch::new(483..581, "break")),
),
];

let renderer = Renderer::styled().theme(OutputTheme::Unicode);
anstream::println!("{}", renderer.render(message));
Expand Down
8 changes: 4 additions & 4 deletions examples/expected_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ fn main() {
,
range: <22, 25>,"#;
let message =
Level::ERROR.header("expected type, found `22`").group(
Group::new().element(
&[Group::new()
.element(Level::ERROR.title("expected type, found `22`"))
.element(
Snippet::source(source)
.line_start(26)
.path("examples/footer.rs")
Expand All @@ -20,8 +21,7 @@ fn main() {
.span(34..50)
.label("while parsing this struct"),
),
),
);
)];

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

fn main() {
let message = Level::ERROR
.header("mismatched types")
.id("E0308")
.group(
Group::new().element(
let message = &[
Group::new()
.element(Level::ERROR.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(Group::new().element(Level::NOTE.title(
Group::new().element(Level::NOTE.title(
"expected type: `snippet::Annotation`\n found type: `__&__snippet::Annotation`",
)));
)),
];

let renderer = Renderer::styled();
anstream::println!("{}", renderer.render(message));
Expand Down
8 changes: 4 additions & 4 deletions examples/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ fn main() {
_ => continue,
}
}"#;
let message = Level::ERROR.header("mismatched types").id("E0308").group(
Group::new().element(
let message = &[Group::new()
.element(Level::ERROR.title("mismatched types").id("E0308"))
.element(
Snippet::source(source)
.line_start(51)
.path("src/format.rs")
Expand All @@ -38,8 +39,7 @@ fn main() {
.span(26..724)
.label("expected enum `std::option::Option`"),
),
),
);
)];

let renderer = Renderer::styled();
anstream::println!("{}", renderer.render(message));
Expand Down
35 changes: 16 additions & 19 deletions examples/highlight_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,23 @@ const CON: Vec<i32> = vec![1, 2, 3]; //~ ERROR E0010
//~| ERROR cannot call non-const method
fn main() {}
"#;
let message = Level::ERROR
.header("allocations are not allowed in constants")
.id("E0010")
.group(
Group::new()
.element(
Snippet::source(source)
.fold(true)
.path("$DIR/E0010-teach.rs")
.annotation(
AnnotationKind::Primary
.span(72..85)
.label("allocation not allowed in constants")
.highlight_source(true),
),
)
.element(
Level::NOTE.title("The runtime heap is not yet available at compile-time, so no runtime heap allocations can be created."),
let message = &[Group::new().element(Level::ERROR.title("allocations are not allowed in constants")
.id("E0010"))
.element(
Snippet::source(source)
.fold(true)
.path("$DIR/E0010-teach.rs")
.annotation(
AnnotationKind::Primary
.span(72..85)
.label("allocation not allowed in constants")
.highlight_source(true),
),
);
)
.element(
Level::NOTE.title("The runtime heap is not yet available at compile-time, so no runtime heap allocations can be created."),

)];

let renderer = Renderer::styled().anonymized_line_numbers(true);
anstream::println!("{}", renderer.render(message));
Expand Down
62 changes: 29 additions & 33 deletions examples/highlight_title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,35 @@ fn main() {
magenta.render_reset()
);

let message = Level::ERROR
.header("mismatched types")
.id("E0308")
.group(
Group::new()
.element(
Snippet::source(source)
.fold(true)
.path("$DIR/highlighting.rs")
.annotation(
AnnotationKind::Primary
.span(553..563)
.label("one type is more general than the other"),
)
.annotation(
AnnotationKind::Context
.span(547..552)
.label("arguments to this function are incorrect"),
),
)
.element(Level::NOTE.title(&title)),
)
.group(
Group::new()
.element(Level::NOTE.title("function defined here"))
.element(
Snippet::source(source)
.fold(true)
.path("$DIR/highlighting.rs")
.annotation(AnnotationKind::Context.span(200..333).label(""))
.annotation(AnnotationKind::Primary.span(194..199)),
),
);
let message = &[
Group::new()
.element(Level::ERROR.title("mismatched types").id("E0308"))
.element(
Snippet::source(source)
.fold(true)
.path("$DIR/highlighting.rs")
.annotation(
AnnotationKind::Primary
.span(553..563)
.label("one type is more general than the other"),
)
.annotation(
AnnotationKind::Context
.span(547..552)
.label("arguments to this function are incorrect"),
),
)
.element(Level::NOTE.pre_styled_title(&title)),
Group::new()
.element(Level::NOTE.title("function defined here"))
.element(
Snippet::source(source)
.fold(true)
.path("$DIR/highlighting.rs")
.annotation(AnnotationKind::Context.span(200..333).label(""))
.annotation(AnnotationKind::Primary.span(194..199)),
),
];

let renderer = Renderer::styled().anonymized_line_numbers(true);
anstream::println!("{}", renderer.render(message));
Expand Down
45 changes: 23 additions & 22 deletions examples/id_hyperlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@ fn main() {
let () = 4; //~ ERROR
}
"#;
let message = Level::ERROR
.header("mismatched types")
.id("E0308")
.id_url("https://doc.rust-lang.org/error_codes/E0308.html")
.group(
Group::new().element(
Snippet::source(source)
.line_start(1)
.path("$DIR/terminal_urls.rs")
.fold(true)
.annotation(
AnnotationKind::Primary
.span(59..61)
.label("expected integer, found `()`"),
)
.annotation(
AnnotationKind::Context
.span(64..65)
.label("this expression has type `{integer}`"),
),
),
);
let message = &[Group::new()
.element(
Level::ERROR
.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")
.fold(true)
.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().theme(OutputTheme::Unicode);
anstream::println!("{}", renderer.render(message));
Expand Down
Loading