macroonz_compiler/expansion/
type_contract.rs1use super::{BINDING_FACT, BindError};
6use crate::bounded::Bounded;
7use crate::diagnostic::{
8 BINDING_FAMILY, Family, LineBody, Observed, Phase, REPAIR_LIMIT, RefusalClass, Refused, Repair,
9};
10use crate::identity::human_projection;
11use core::fmt;
12
13impl BindError {
14 #[must_use]
18 pub const fn slot(&self) -> u8 {
19 match self {
20 Self::ClosureProvedAgainstAnotherPlan { .. } => 0,
21 Self::ExplanationAnsweredOverAnotherPlan { .. } => 1,
22 Self::ExplanationAnsweredOverAnotherClosure { .. } => 2,
23 }
24 }
25}
26
27impl fmt::Display for BindError {
28 fn fmt(&self, into: &mut fmt::Formatter<'_>) -> fmt::Result {
29 into.write_str(match self {
30 Self::ClosureProvedAgainstAnotherPlan { .. } => {
31 "the closure proves a rendering against a plan other than the one bound beside it"
32 }
33 Self::ExplanationAnsweredOverAnotherPlan { .. } => {
34 "the explanation was answered over a plan other than the one bound beside it"
35 }
36 Self::ExplanationAnsweredOverAnotherClosure { .. } => {
37 "the explanation was answered over a proof other than the one bound beside it"
38 }
39 })
40 }
41}
42
43impl core::error::Error for BindError {}
44
45impl Refused for BindError {
46 const PHASE: Phase = Phase::Binding;
47 const FAMILY: Family = BINDING_FAMILY;
48
49 fn class(&self) -> RefusalClass {
50 RefusalClass::ExpansionNotBound
51 }
52
53 fn first(&self) -> String {
54 self.to_string()
55 }
56
57 fn observed(&self) -> Observed {
59 Observed::IdentityDisagreement
60 }
61
62 fn body(&self) -> LineBody {
66 LineBody::SingleCause
67 }
68
69 fn related(&self) -> Vec<Vec<u8>> {
71 Vec::new()
72 }
73
74 fn repairs(&self) -> Bounded<Repair, REPAIR_LIMIT> {
78 Bounded::from_array([Repair {
79 declared_by: BINDING_FACT,
80 description: human_projection!(
81 "an expansion binds the plan its proof was taken against and the explanation answered over the two, so a proof or an explanation belonging to another expansion is refused rather than bound under one identity"
82 ),
83 }])
84 }
85}