forked from rust-lang/annotate-snippets-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_error.rs
37 lines (33 loc) · 1.29 KB
/
custom_error.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
36
37
use annotate_snippets::renderer::OutputTheme;
use annotate_snippets::{AnnotationKind, Group, Level, Renderer, Snippet};
fn main() {
let source = r#"//@ compile-flags: -Ztreat-err-as-bug
//@ failure-status: 101
//@ error-pattern: aborting due to `-Z treat-err-as-bug=1`
//@ error-pattern: [eval_static_initializer] evaluating initializer of static `C`
//@ normalize-stderr: "note: .*\n\n" -> ""
//@ normalize-stderr: "thread 'rustc' panicked.*:\n.*\n" -> ""
//@ rustc-env:RUST_BACKTRACE=0
#![crate_type = "rlib"]
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)
.origin("$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));
}