macroonz_compiler/host/
type_contract.rs1use super::types::{CaptureError, EmissionError, Emittable};
4use crate::closure::PartitionCargo;
5use crate::expansion::Expansion;
6use crate::kind::Kind;
7use crate::token::CaptureBound;
8use core::fmt;
9
10impl CaptureError {
11 #[must_use]
15 pub const fn slot(&self) -> u8 {
16 match self {
17 Self::Unbounded { .. } => 0,
18 Self::Unread { .. } => 1,
19 }
20 }
21}
22
23impl From<CaptureBound> for CaptureError {
24 fn from(bound: CaptureBound) -> Self {
25 Self::Unbounded { bound }
26 }
27}
28
29impl fmt::Display for CaptureError {
30 fn fmt(&self, into: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match self {
32 Self::Unbounded { bound } => write!(into, "{bound}"),
33 Self::Unread { cause, .. } => write!(into, "{cause}"),
34 }
35 }
36}
37
38impl core::error::Error for CaptureError {
39 fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
40 match self {
41 Self::Unbounded { bound } => Some(bound),
42 Self::Unread { cause, .. } => Some(cause),
43 }
44 }
45}
46
47impl fmt::Display for EmissionError {
48 fn fmt(&self, into: &mut fmt::Formatter<'_>) -> fmt::Result {
49 match self {
50 Self::NumberRejected { spelling } => write!(
51 into,
52 "the compiler host rejected the admitted numeric literal `{spelling}`"
53 ),
54 Self::NulTerminatedTextRejected => into
55 .write_str("the compiler host rejected admitted NUL-terminated literal material"),
56 Self::SourceSpanRosterContradiction => into.write_str(
57 "the generated tree's preserved source roster does not match its token denominator",
58 ),
59 Self::SourceSpanUnresolved(refusal) => write!(
60 into,
61 "the compiler host could not resolve one preserved source span: {refusal}"
62 ),
63 }
64 }
65}
66
67impl core::error::Error for EmissionError {
68 fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
69 match self {
70 Self::SourceSpanUnresolved(refusal) => Some(refusal),
71 Self::NumberRejected { .. }
72 | Self::NulTerminatedTextRejected
73 | Self::SourceSpanRosterContradiction => None,
74 }
75 }
76}
77
78impl<K: Kind> Emittable for Expansion<K> {
79 fn cargos(&self) -> impl Iterator<Item = &PartitionCargo> {
81 core::iter::once(self.emit())
82 }
83}