miden_diagnostics/
lib.rs

1mod codemap;
2mod config;
3mod diagnostic;
4mod emitter;
5mod filename;
6mod handler;
7mod index;
8mod source;
9mod span;
10
11pub use codespan::Location;
12pub use codespan::{ByteIndex, ByteOffset};
13pub use codespan::{ColumnIndex, ColumnNumber, ColumnOffset};
14pub use codespan::{Index, Offset};
15pub use codespan::{LineIndex, LineNumber, LineOffset};
16pub use codespan::{RawIndex, RawOffset};
17
18pub use codespan_reporting::diagnostic::{LabelStyle, Severity};
19pub use codespan_reporting::files::{Error, Files};
20pub use codespan_reporting::term;
21
22pub use miden_diagnostics_macros::*;
23
24pub use self::codemap::CodeMap;
25pub use self::config::{DiagnosticsConfig, Verbosity};
26pub use self::diagnostic::InFlightDiagnostic;
27pub use self::emitter::{CaptureEmitter, DefaultEmitter, Emitter, NullEmitter};
28pub use self::filename::FileName;
29pub use self::handler::DiagnosticsHandler;
30pub use self::index::SourceIndex;
31pub use self::source::{SourceFile, SourceId};
32pub use self::span::{SourceSpan, Span, Spanned};
33
34pub type Diagnostic = codespan_reporting::diagnostic::Diagnostic<SourceId>;
35pub type Label = codespan_reporting::diagnostic::Label<SourceId>;
36
37/// [ToDiagnostic] should be implemented on types which can be converted to a [Diagnostic].
38///
39/// This is largely intended for implementations of [std::error::Error], but may be implemented
40/// for any type that has a canonical [Diagnostic] representation.
41pub trait ToDiagnostic {
42    fn to_diagnostic(self) -> Diagnostic;
43}
44impl ToDiagnostic for Diagnostic {
45    #[inline(always)]
46    fn to_diagnostic(self) -> Diagnostic {
47        self
48    }
49}
50
51#[doc(hidden)]
52pub struct FatalErrorMarker;
53
54/// Used as a return value to signify a fatal error occurred
55#[derive(Copy, Clone, Debug)]
56#[must_use]
57pub struct FatalError;
58impl FatalError {
59    pub fn raise(self) -> ! {
60        std::panic::resume_unwind(Box::new(FatalErrorMarker))
61    }
62}
63impl core::fmt::Display for FatalError {
64    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65        write!(f, "The compiler has encountered a fatal error")
66    }
67}