-
Notifications
You must be signed in to change notification settings - Fork 771
Expand file tree
/
Copy pathconst_error.rs
More file actions
30 lines (27 loc) · 780 Bytes
/
const_error.rs
File metadata and controls
30 lines (27 loc) · 780 Bytes
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
use super::*;
#[derive(Clone, Copy, Debug)]
pub(crate) enum ConstError<'src> {
Backtick(Token<'src>),
FunctionCall(Name<'src>),
Variable(Name<'src>),
}
impl<'src> ConstError<'src> {
pub(crate) fn context(self) -> Token<'src> {
match self {
Self::Backtick(token) => token,
Self::FunctionCall(name) | Self::Variable(name) => name.token,
}
}
}
impl Display for ConstError<'_> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Self::Backtick(_) => write!(f, "cannot call backticks in const context"),
Self::FunctionCall(_) => write!(f, "cannot call functions in const context"),
Self::Variable(name) => write!(
f,
"cannot access non-const variable `{name}` in const context"
),
}
}
}