implicit_predicates_gen/
error.rs1use std::fmt;
4
5use proc_macro2::Span;
6
7use crate::parse::Position;
8
9#[derive(Clone, Debug, PartialEq, Eq)]
12pub struct Error {
13 pub file: String,
15 pub line: usize,
17 pub column: usize,
19 pub message: String,
21}
22
23impl Error {
24 pub(crate) fn at(file: &str, position: Position, message: impl Into<String>) -> Self {
26 Error {
27 file: file.to_string(),
28 line: position.line,
29 column: position.column,
30 message: message.into(),
31 }
32 }
33}
34
35impl fmt::Display for Error {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 write!(
38 f,
39 "{}:{}:{}: {}",
40 self.file, self.line, self.column, self.message
41 )
42 }
43}
44
45impl std::error::Error for Error {}
46
47pub(crate) struct Diag {
49 pub(crate) line: usize,
50 pub(crate) column: usize,
51 pub(crate) message: String,
52}
53
54pub(crate) type Res<T> = Result<T, Diag>;
55
56pub(crate) fn diag(span: Span, message: impl Into<String>) -> Diag {
58 let start = span.start();
59 Diag {
60 line: start.line,
61 column: start.column + 1,
62 message: message.into(),
63 }
64}