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
use runestick::{SourceId, Span};
use std::error;
use std::fmt;
use thiserror::Error;
#[derive(Debug, Clone, Copy)]
pub struct Warning {
pub(super) last: Option<usize>,
pub(super) source_id: SourceId,
pub(super) kind: WarningKind,
}
impl Warning {
pub fn source_id(&self) -> SourceId {
self.source_id
}
pub fn kind(&self) -> &WarningKind {
&self.kind
}
pub fn into_kind(self) -> WarningKind {
self.kind
}
pub fn span(&self) -> Span {
match &self.kind {
WarningKind::NotUsed { span, .. } => *span,
WarningKind::LetPatternMightPanic { span, .. } => *span,
WarningKind::TemplateWithoutExpansions { span, .. } => *span,
WarningKind::RemoveTupleCallParams { span, .. } => *span,
WarningKind::UnecessarySemiColon { span, .. } => *span,
}
}
}
impl fmt::Display for Warning {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.kind, f)
}
}
impl error::Error for Warning {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
self.kind.source()
}
}
#[derive(Debug, Clone, Copy, Error)]
pub enum WarningKind {
#[error("not used")]
NotUsed {
span: Span,
context: Option<Span>,
},
#[error("pattern might panic")]
LetPatternMightPanic {
span: Span,
context: Option<Span>,
},
#[error("using a template string without expansions, like `Hello World`")]
TemplateWithoutExpansions {
span: Span,
context: Option<Span>,
},
#[error("call paramters are not needed here")]
RemoveTupleCallParams {
span: Span,
variant: Span,
context: Option<Span>,
},
#[error("unnecessary semicolon")]
UnecessarySemiColon {
span: Span,
},
}