macroonz_compiler/stamp/
type_contract.rs1use super::{StampError, TransportedReach, Visibility};
7use crate::bounded::Overflow;
8
9impl Visibility {
10 #[must_use]
19 pub const fn transported(self) -> TransportedReach {
20 match self {
21 Self::Private | Self::Module => TransportedReach::Enclosing,
22 Self::Parent => TransportedReach::Ancestor,
23 Self::Crate => TransportedReach::Crate,
24 Self::Public => TransportedReach::Public,
25 }
26 }
27}
28
29impl From<Overflow> for StampError {
33 fn from(overflow: Overflow) -> Self {
34 Self::TokensUnbounded { overflow }
35 }
36}
37
38impl core::fmt::Display for StampError {
39 fn fmt(&self, into: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
40 match self {
41 Self::NotAnIdentifier => write!(
42 into,
43 "a spelling this stamp writes as a token is not one Rust identifier"
44 ),
45 Self::PathEmpty => write!(into, "a spelled path names no segment, so it names nothing"),
46 Self::PathUnbounded { overflow } => write!(
47 into,
48 "a spelled path carries {} segments where at most {} fit",
49 overflow.offered, overflow.capacity
50 ),
51 Self::PatternEmpty => {
52 write!(into, "a pattern declares no part, so it declares no shape")
53 }
54 Self::PatternUnbounded { overflow } => write!(
55 into,
56 "a pattern declares {} parts where at most {} fit",
57 overflow.offered, overflow.capacity
58 ),
59 Self::SeatNameDoubled { at } => write!(
60 into,
61 "the seat at part {at} carries a name an earlier seat already binds"
62 ),
63 Self::SitesAbsent => write!(
64 into,
65 "a stamp covers no site, and a definition nobody invokes has no reader"
66 ),
67 Self::SitesUnbounded { overflow } => write!(
68 into,
69 "a stamp covers {} sites where at most {} fit",
70 overflow.offered, overflow.capacity
71 ),
72 Self::SiteNameDoubled { at } => write!(
73 into,
74 "the site at position {at} carries a name an earlier site already has"
75 ),
76 Self::ArgumentsUnbounded { overflow } => write!(
77 into,
78 "a site carries {} arguments where at most {} fit",
79 overflow.offered, overflow.capacity
80 ),
81 Self::ArgumentsUnmatched {
82 at,
83 seats,
84 supplied,
85 } => write!(
86 into,
87 "the site at position {at} supplies {supplied} arguments for {seats} declared seats"
88 ),
89 Self::ReachUnseated { at } => write!(
90 into,
91 "the site at position {at} declares a reach its pattern gives no coordinate to"
92 ),
93 Self::SeatNotPlanned { role_slot } => write!(
94 into,
95 "the plan declares no member under the seat at roster position {role_slot}"
96 ),
97 Self::DestinationNotArtifact { role_slot } => write!(
98 into,
99 "the member at roster position {role_slot} lands somewhere other than an artifact"
100 ),
101 Self::TokensUnbounded { overflow } => write!(
102 into,
103 "a rendered tree carries {} tokens where at most {} fit",
104 overflow.offered, overflow.capacity
105 ),
106 }
107 }
108}
109
110impl core::error::Error for StampError {
111 fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
112 match self {
113 Self::PathUnbounded { overflow }
114 | Self::PatternUnbounded { overflow }
115 | Self::SitesUnbounded { overflow }
116 | Self::ArgumentsUnbounded { overflow }
117 | Self::TokensUnbounded { overflow } => Some(overflow),
118 Self::NotAnIdentifier
119 | Self::PathEmpty
120 | Self::PatternEmpty
121 | Self::SeatNameDoubled { .. }
122 | Self::SitesAbsent
123 | Self::SiteNameDoubled { .. }
124 | Self::ArgumentsUnmatched { .. }
125 | Self::ReachUnseated { .. }
126 | Self::SeatNotPlanned { .. }
127 | Self::DestinationNotArtifact { .. } => None,
128 }
129 }
130}