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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
extern crate termcolor;
extern crate codemap;
extern crate atty;
use codemap::Span;
mod lock;
mod snippet;
mod styled_buffer;
mod emitter;
pub use emitter::{ ColorConfig, Emitter };
use termcolor::{ ColorSpec, Color };
#[derive(Clone, Debug)]
pub struct Diagnostic {
pub level: Level,
pub message: String,
pub code: Option<String>,
pub spans: Vec<SpanLabel>,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Level {
Bug,
Error,
Warning,
Note,
Help,
}
impl ::std::fmt::Display for Level {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
self.to_str().fmt(f)
}
}
impl Level {
fn color(self) -> ColorSpec {
let mut spec = ColorSpec::new();
use self::Level::*;
match self {
Bug | Error => {
spec.set_fg(Some(Color::Red))
.set_intense(true);
}
Warning => {
spec.set_fg(Some(Color::Yellow))
.set_intense(cfg!(windows));
}
Note => {
spec.set_fg(Some(Color::Green))
.set_intense(true);
}
Help => {
spec.set_fg(Some(Color::Cyan))
.set_intense(true);
}
}
spec
}
pub fn to_str(self) -> &'static str {
use self::Level::*;
match self {
Bug => "error: internal compiler error",
Error => "error",
Warning => "warning",
Note => "note",
Help => "help",
}
}
}
#[derive(Clone, Debug)]
pub struct SpanLabel {
pub span: Span,
pub label: Option<String>,
pub style: SpanStyle,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum SpanStyle {
Primary,
Secondary,
}