forked from rust-lang/annotate-snippets-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighlight_source.rs
35 lines (31 loc) · 1.2 KB
/
highlight_source.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use annotate_snippets::{AnnotationKind, Group, Level, Renderer, Snippet};
fn main() {
let source = r#"//@ compile-flags: -Z teach
#![allow(warnings)]
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)
.origin("$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));
}