byteor_pipeline_lower/
error.rs

1#[cfg(feature = "alloc")]
2use alloc::vec::Vec;
3
4#[cfg(feature = "alloc")]
5use crate::diagnostics::LowerDiagnosticV2;
6
7/// Lowering result type.
8pub type Result<T> = core::result::Result<T, LowerError>;
9
10/// Errors produced during lowering.
11#[derive(Debug, Clone, PartialEq, Eq)]
12#[non_exhaustive]
13pub enum LowerError {
14    /// Invalid authoring plan or unsupported lowering shape.
15    Invalid(&'static str),
16    /// Lowering target or feature is unsupported.
17    Unsupported(&'static str),
18    /// Structured diagnostics for v2 lowering failures.
19    #[cfg(feature = "alloc")]
20    DiagnosticsV2(Vec<LowerDiagnosticV2>),
21}
22
23impl core::fmt::Display for LowerError {
24    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
25        match self {
26            LowerError::Invalid(msg) => write!(f, "invalid lowering input: {msg}"),
27            LowerError::Unsupported(msg) => write!(f, "unsupported lowering input: {msg}"),
28            #[cfg(feature = "alloc")]
29            LowerError::DiagnosticsV2(diagnostics) => {
30                if let Some(LowerDiagnosticV2::Rejected { message, .. }) = diagnostics.first() {
31                    write!(f, "invalid lowering input: {message}")
32                } else {
33                    write!(f, "invalid lowering input: structured diagnostics available")
34                }
35            }
36        }
37    }
38}
39
40#[cfg(feature = "std")]
41impl std::error::Error for LowerError {}