machine_check_machine/support/
machine_error.rs1use crate::wir::WSpan;
2
3#[derive(thiserror::Error, Debug, Clone)]
4pub enum ErrorType {
5 #[error("machine-check: Cannot parse module without content")]
6 ModuleWithoutContent,
7
8 #[error("machine-check error: Unknown macro")]
9 UnknownMacro,
10 #[error("{0}")]
11 MacroError(String),
12 #[error("{0}")]
13 MacroParseError(syn::Error),
14 #[error("machine-check: {0}")]
15 UnsupportedConstruct(String),
16 #[error("machine-check: {0}")]
17 IllegalConstruct(String),
18 #[error("machine-check: Could not infer variable type")]
19 InferenceFailure,
20 #[error("machine-check (concrete conversion): {0}")]
21 ConcreteConversionError(String),
22 #[error("machine-check (forward conversion): {0}")]
23 ForwardConversionError(String),
24 #[error("machine-check (backward conversion): {0}")]
25 BackwardConversionError(String),
26
27 #[error("machine-check: {0}")]
28 DescriptionError(String),
29
30 #[error("machine-check internal error (SSA translation): {0}")]
31 SsaInternal(String),
32 #[error("machine-check internal error (forward translation): {0}")]
33 ForwardInternal(String),
34 #[error("machine-check internal error (backward translation): {0}")]
35 BackwardInternal(String),
36 #[error("machine-check internal error (rules): {0}")]
37 RulesInternal(String),
38}
39
40#[derive(thiserror::Error, Debug, Clone)]
41#[error("{span:?}: {ty}")]
42pub struct Error {
43 pub(crate) ty: ErrorType,
44 pub(crate) span: WSpan,
45}
46
47impl Error {
48 pub fn new(ty: ErrorType, span: WSpan) -> Self {
49 Self { ty, span }
50 }
51
52 pub fn into_syn_error(self) -> syn::Error {
53 syn::Error::new_spanned(self.span.syn_delimiters(), self.ty.to_string())
54 }
55}