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
use std::fmt;
use crate::span::Span;
#[derive(Clone, Copy)]
pub struct ParseWarning {
pub kind: ParseWarningKind,
pub span: Span,
}
#[derive(Debug, Clone, Copy)]
pub enum ParseWarningKind {
Deprecation(DeprecationWarning),
}
impl ParseWarningKind {
pub(crate) fn at(self, span: Span) -> ParseWarning {
ParseWarning { kind: self, span }
}
}
impl fmt::Display for ParseWarning {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let ParseWarningKind::Deprecation(warning) = &self.kind;
if let Some(std::ops::Range { start, end }) = self.span.range() {
write!(f, "{warning}\n at {start}..{end}")
} else {
write!(f, "{warning}")
}
}
}
impl fmt::Display for ParseWarningKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let ParseWarningKind::Deprecation(c) = self;
c.fmt(f)
}
}
#[derive(Debug, Clone, Copy)]
pub enum DeprecationWarning {
Dot,
}
impl fmt::Display for DeprecationWarning {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
DeprecationWarning::Dot => {
f.write_str("This syntax is deprecated. Use `.` without the brackets.")
}
}
}
}