tin_lang/
error.rs

1//! Common error types and utilities.
2use std::result;
3
4use ir;
5use parser;
6
7/// An error that occurs while interacting with Tin.
8#[derive(Debug, Fail, PartialEq)]
9pub enum Error {
10    /// Parsing the source code failed.
11    #[fail(display = "parser error")]
12    Parser(#[cause] parser::Error),
13    /// Semantically understanding the source code failed.
14    #[fail(display = "IR error")]
15    Ir(#[cause] ir::Error),
16}
17
18/// A convenience result wrapper for the [`Error`] type.
19pub type Result<A> = result::Result<A, Error>;
20
21impl From<ir::Error> for Error {
22    fn from(err: ir::Error) -> Self {
23        Error::Ir(err)
24    }
25}
26
27impl From<parser::Error> for Error {
28    fn from(err: parser::Error) -> Self {
29        Error::Parser(err)
30    }
31}