1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
//! Exhaustiveness fence over SPEC.md §18.1's error taxonomy.
//!
//! §18.1 is explicit: "Closed and normative: every variant this
//! specification names appears here exactly once." For each of the ten
//! error types this file defines a function that takes a value of that
//! type and `match`es it with **no wildcard arm**. That absence is the
//! whole point: a `_` arm would silently keep compiling the day a variant
//! is added or removed, defeating the fence. If a variant list here ever
//! stops matching the crate's, this file stops *compiling* — do not "fix"
//! that by adding a `_` arm; it means either SPEC.md or the crate moved
//! and the taxonomy needs a ruling, per CLAUDE.md's frozen-spec rule.
//!
//! Each fence function is referenced (as a bare function pointer) from a
//! `#[test]`, rather than called on a constructed instance — several
//! variants carry fields (e.g. `ConnectionLost::PeerClosed`'s `reason`)
//! whose exact Rust type §18.1 does not spell out, and guessing one to
//! build a dummy value would risk a false-negative compile failure
//! unrelated to the taxonomy itself. Taking the function pointer is enough
//! to force the match to be type-checked (and to keep it from being
//! flagged dead code under `-D warnings`) without that risk. Where §18.1
//! *does* give an explicit field type (`WriteError::Reset(u64)`,
//! `ReadError::Reset(u64)`), the match arm below annotates the binding
//! with that type, so a field-type drift also fails to compile.
//!
//! `ConfigError` is the one exception to "from §18.1": per ruling 44
//! (grep `ConfigError` in SPEC.md), it is a **configuration** error for
//! `set_persistent_keepalive` and is deliberately kept outside §18.1's
//! protocol-error taxonomy — no peer, packet, or connection state is
//! involved. It is checked here against §16.2 instead.
use *;
/// NOT an exhaustiveness fence, despite the shape of its neighbours.
/// `WriteError` is `#[non_exhaustive]`, so out of crate this cannot be
/// one — see the comment on `match_write_error`'s wildcard arm. The real
/// fence is `src/error.rs::tests::write_error_is_exhaustive_in_crate`.
/// Kept only to check the three known variants' payload shapes.
// =======================================================================
// The fence functions themselves.
// =======================================================================
/// SPEC.md §18.1: `ConnectError::{AlreadyConnected, TimedOut, Local}` —
/// exactly three variants, all unit. `AlreadyConnected` is returned by
/// `connect()` itself and also as the tie-break-loser resolution of an
/// in-flight `Connecting` (§6.4's PENDING branch, §6.7); `TimedOut` is
/// initial-connect give-up at `HANDSHAKE_GIVEUP` (§5.5); `Local`
/// **[RATIFIED 2026/08/15 — ruling 72]** is *our own* `Identity::open()`
/// failing — a locked enclave, a hardware fault.
/// SPEC.md §18.1: `IntroError::{Expired, Evicted, Internal, Malformed,
/// Local, EndpointDropped}` — exactly **six** variants, all unit.
/// `Superseded` appears nowhere (§6.3) — it is still not a variant to add
/// here. `Local` **[RATIFIED 2026/08/15 — ruling 72]** is *our own*
/// provider failing, and is the opposite of `Malformed` in every way that
/// matters: the chain is left **parked** and a retry can still succeed,
/// where a `Malformed` chain is discarded and the verdict is definitive.
///
/// **[RATIFIED 2026/08/18 — ruling 261]** `Evicted` is the sixth. This
/// doc read *"exactly five variants"* and it was the fence §18.1's closure
/// is enforced by, so the count is corrected here with the enum. §6.3's two
/// cap rules displace a parked chain **before** its TTL, and every staged
/// verb reported that as `Expired` — not a vague message but a false one,
/// naming a 15 s timeout for a microsecond-scale loss of a race for a slot.
///
/// **§18.1 itself still lists five and owes the amendment** — the section
/// is normative and this file is the fence for it, so until SPEC.md carries
/// `Evicted` the two disagree by exactly this ruling.
/// SPEC.md §18.1: `AuthError::{Replay, HandshakeFailed, Expired, Local,
/// EndpointDropped}` — exactly five variants, all unit. `HandshakeFailed`
/// is called out as "the only variant in the staged taxonomy that is a
/// security signal"; `Local` **[RATIFIED 2026/08/15 — ruling 78]** exists
/// so that *our own* provider failing does not fall through to it and
/// report the peer as an attacker.
/// SPEC.md §18.1: `AcceptError::{Stale, EndpointDropped}` — exactly two
/// variants, both unit. Explicitly **not** four: `Expired` and
/// `AlreadyConnected` are both called out by name as absent ("There is no
/// `Expired` here ... There is no `AlreadyConnected`").
/// SPEC.md §18.1: `ConnectionLost::{TimedOut, NonceExhausted,
/// LocallyClosed, PeerClosed { code, reason }, ProtocolViolation { code },
/// Replaced, EndpointDropped}` — exactly seven variants. `PeerClosed` and
/// `ProtocolViolation` are the two struct-shaped ones (the shape itself —
/// field names and arity — is what this match's patterns assert); the
/// other five are unit.
/// SPEC.md §18.1: `WriteError::{Reset(u64), ConnectionLost(ConnectionLost),
/// Finished}` — exactly three *documented* variants, but this is the ONE
/// type in the taxonomy ruling 61 marks `#[non_exhaustive]` (§19 reserves
/// `Stopped` for the deferred STOP_SENDING round, so this type demonstrably
/// will gain a variant). `#[non_exhaustive]` has no effect within the
/// defining crate, but this file is compiled as a separate crate (anything
/// under `tests/` is), and from outside the defining crate the compiler
/// *requires* a wildcard arm on a non_exhaustive enum's match — there is no
/// way to satisfy rustc here without one, unlike every other function in
/// this file. The `_` below is therefore load-bearing, not a shortcut: it
/// stays loud by panicking rather than silently doing nothing, so an
/// actually-new variant is still caught (at test-run time, since a compile
/// time catch is exactly what `#[non_exhaustive]` forecloses here).
/// SPEC.md §18.1: `ReadError::{Reset(u64), ConnectionLost(ConnectionLost)}`
/// — exactly two variants. `Reset(code)` is the peer's RESET_STREAM (§9.6).
/// SPEC.md §18.1: `MessageError::{TooLarge, ConnectionLost(ConnectionLost)}`
/// — exactly two variants. `TooLarge`: payload > `MESSAGE_RECV_MAX` at the
/// handle (§9.8).
/// SPEC.md §18.1: `DatagramError::{TooLarge,
/// ConnectionLost(ConnectionLost)}` — exactly two variants. `TooLarge`:
/// payload > `MAX_DATAGRAM_PAYLOAD` at the handle (§11.4).
/// `ConfigError` is deliberately **outside** §18.1's closed taxonomy
/// (ruling 44: "`ConfigError` is a **configuration** error and
/// deliberately sits outside §18.1's protocol-error taxonomy ... no peer,
/// no packet, and no connection state is involved, and nothing about it is
/// observable on the wire"). Its homes are §16.2 and §10.2:
/// `set_persistent_keepalive` returns `Result<(), ConfigError>` —
/// `KeepaliveTooShort` (below 1 s, the floor, ruling 42) and
/// `KeepaliveTooLong` (at or above `DEAD_TIMEOUT`, the ceiling, ruling
/// 40) — and `Config::with_flow_windows` returns
/// `Result<Config, ConfigError>` with ruling 259(viii)'s three window
/// refusals: `WindowTooSmall` (below the ratified initial),
/// `WindowTooLarge` (above `2^62 - 1`), `StreamWindowAboveConnection`
/// (the pair inverted). Each variant names the bound it violated.