forked from rust-lang/annotate-snippets-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_level.rs
71 lines (66 loc) · 2.26 KB
/
custom_level.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use annotate_snippets::renderer::OutputTheme;
use annotate_snippets::{AnnotationKind, Group, Level, Patch, Renderer, Snippet};
fn main() {
let source = r#"// Regression test for issue #114529
// Tests that we do not ICE during const eval for a
// break-with-value in contexts where it is illegal
#[allow(while_true)]
fn main() {
[(); {
while true {
break 9; //~ ERROR `break` with value from a `while` loop
};
51
}];
[(); {
while let Some(v) = Some(9) {
break v; //~ ERROR `break` with value from a `while` loop
};
51
}];
while true {
break (|| { //~ ERROR `break` with value from a `while` loop
let local = 9;
});
}
}
"#;
let message = Level::ERROR
.header("`break` with value from a `while` loop")
.id("E0571")
.group(
Group::new().element(
Snippet::source(source)
.line_start(1)
.origin("$DIR/issue-114529-illegal-break-with-value.rs")
.fold(true)
.annotation(
AnnotationKind::Primary
.span(483..581)
.label("can only break with a value inside `loop` or breakable block"),
)
.annotation(
AnnotationKind::Context
.span(462..472)
.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)
.origin("$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));
}