Skip to main content

varar_core/
diagnostics.rs

1//! Diagnostics produced by the planner — port of the subset of `diagnostics.ts`
2//! that `Plan` needs / `Diagnostics.java`.
3
4use crate::span::Span;
5
6/// Diagnostic severity. Only `Error` is constructed today.
7#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8pub enum Severity {
9    Error,
10    Warning,
11    Info,
12}
13
14/// The closed set of diagnostic codes the planner produces. `Ord` follows the
15/// Java enum's declaration order (ordinal), matching its sort semantics.
16#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
17pub enum DiagnosticCode {
18    AmbiguousMatch,
19    ErrorFenceWithoutStep,
20    Drift,
21}
22
23/// One diagnostic: its code, severity, and the source span it points at.
24#[derive(Clone, Copy, Debug, PartialEq, Eq)]
25pub struct Diagnostic {
26    pub code: DiagnosticCode,
27    pub severity: Severity,
28    pub span: Span,
29}
30
31/// Builds an `ambiguous-match` diagnostic pointing at `span`.
32pub fn ambiguous_match(span: Span) -> Diagnostic {
33    Diagnostic {
34        code: DiagnosticCode::AmbiguousMatch,
35        severity: Severity::Error,
36        span,
37    }
38}
39
40/// Builds an `error-fence-without-step` diagnostic pointing at `span`.
41pub fn error_fence_without_step(span: Span) -> Diagnostic {
42    Diagnostic {
43        code: DiagnosticCode::ErrorFenceWithoutStep,
44        severity: Severity::Error,
45        span,
46    }
47}