use crate::common::FileId;
use crate::common::{BUG_URL, Diagnostic, InternalError};
use codespan_reporting::diagnostic::Diagnostic as CsDiagnostic;
use thiserror::Error;
#[non_exhaustive]
#[derive(Debug, Error)]
pub enum CodegenError {
#[error(transparent)]
Internal(#[from] InternalError),
}
impl CodegenError {
pub(crate) fn internal(detail: impl Into<String>) -> Self {
Self::Internal(InternalError::new("codegen", detail, BUG_URL))
}
}
impl Diagnostic for CodegenError {
fn to_diagnostic(&self) -> CsDiagnostic<FileId> {
match self {
CodegenError::Internal(ie) => ie.to_diagnostic(),
}
}
fn is_internal(&self) -> bool {
matches!(self, CodegenError::Internal(_))
}
}