deduxit 0.3.0

Logic suites, linear logic first: decides, checks, proves step by step and exports sequents of classical and intuitionistic linear logic, and ordinary propositional logic through its embeddings.
Documentation
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
// deduxit © Fabian Lukas Grubmüller 2026
// Licensed under the EUPL

/// Errors printed with formulas for their occurrence ids.
pub(crate) mod describe;
/// The error type for text that is not a sequent.
#[cfg(feature = "parse")]
mod parse;

pub(crate) use describe::Subject;
pub use describe::{Described, Owner};
#[cfg(feature = "parse")]
pub use parse::ParseError;

use crate::limits::{Refusal, Space};
use crate::linear::fragment::{Fragment, Mode};
use crate::linear::nets::NetError;
use crate::linear::occurrences::ShapeError;
use crate::linear::proofs::CheckError;
use crate::linear::search::{Engine, NotTaken};
use crate::linear::sequents::fo::SymbolFault;
use thiserror::Error;

/// Everything that can go wrong in a call of this crate, as one family:
/// [`kind`](Self::kind) says what sort of failure it is, so that a refusal
/// is never read as a fault, and [`code`](Self::code) is the stable reason
/// a program branches on. The specific types a caller may match on
/// ([`CheckError`], [`NetError`], [`ShapeError`], the session's
/// `StepError`, the parser's `ParseError`, Rocq's `Unsupported`) are
/// variants of it, converted without loss.
///
/// # JSON
///
/// With the feature `serialize` an error is written (never read) as
/// `{"code": …, "kind": …, "message": …, "setting": …, "details": …}`:
/// `code` is one of [`CODES`](Self::CODES), stable from the first release,
/// which a client branches on, accepting a code it does not know by its
/// `kind`; `kind` is the [`ErrorKind`] in snake case; `message` the
/// English text, with formulas when written through
/// [`describe`](Self::describe); `setting`, present only where a bound
/// refused the call, the settings key that lifts it
/// ([`setting`](Self::setting)); and `details` the variant's fields, or
/// the wrapped error's (a `ParseError` its span in bytes and in UTF-16
/// code units, its line and character and what was expected; a
/// [`CheckError`] the node, its rule as a proof writes it, the fault and
/// the premises' sequents; a [`Refusal`] its `kind` and fields).
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq, Eq, Error)]
pub enum Error {
    /// The input is not a sequent: where and why.
    ///
    /// Needs the cargo feature `parse`.
    #[cfg(feature = "parse")]
    #[error("cannot parse the sequent: {0}")]
    Parse(Box<ParseError>),
    /// The input is not an LLTP problem, for the reason given.
    ///
    /// Needs the cargo feature `parse`.
    #[cfg(feature = "parse")]
    #[error("not an LLTP problem: {message}")]
    #[non_exhaustive]
    Lltp {
        /// What is wrong with it.
        message: String,
    },
    /// The input is not a coverability problem in Mist's `.spec` format,
    /// for the reason given.
    ///
    /// Needs the cargo feature `parse`.
    #[cfg(feature = "parse")]
    #[error("not a .spec problem: {message}")]
    #[non_exhaustive]
    Spec {
        /// What is wrong with it.
        message: String,
    },
    /// The input is not a TPTP problem of propositional logic, for the
    /// reason given.
    ///
    /// Needs the cargo feature `parse`.
    #[cfg(feature = "parse")]
    #[error("not a TPTP problem: {message}")]
    #[non_exhaustive]
    Tptp {
        /// What is wrong with it.
        message: String,
    },
    /// An LLTP or TPTP file has more than one conjecture (the name of the
    /// second given), which this crate does not read as one sequent.
    ///
    /// Needs the cargo feature `parse`.
    #[cfg(feature = "parse")]
    #[error("the file has a second conjecture, `{second}`, and is read with one only")]
    #[non_exhaustive]
    SeveralConjectures {
        /// The name of the second clause with the role `conjecture`.
        second: String,
    },
    /// A name that names none of the values of its kind, such as a mode
    /// or a fragment read from text.
    #[error("unknown {what} `{name}`: {}", or_list(.known))]
    #[non_exhaustive]
    UnknownName {
        /// What the name was to name: `mode`, `fragment`.
        what: &'static str,
        /// The name read.
        name: Box<str>,
        /// Every name of that kind.
        known: &'static [&'static str],
    },
    /// A generated family has no instance of the size asked for.
    ///
    /// Needs the cargo feature `parse`.
    #[cfg(feature = "parse")]
    #[error(
        "the family {family} has no instance of size {size}: its sizes are {}at least {least}",
        if *.powers_of_two { "the powers of two " } else { "" }
    )]
    #[non_exhaustive]
    FamilySize {
        /// The family's name.
        family: &'static str,
        /// The size asked for.
        size: u32,
        /// The least size it has.
        least: u32,
        /// Whether its sizes are the powers of two.
        powers_of_two: bool,
    },
    /// An option's value is not one the output can take: a Rocq lemma
    /// that is no identifier.
    #[error("{key}: {message}")]
    #[non_exhaustive]
    InvalidOption {
        /// The option, as the settings name it: `rocq.lemma`.
        key: &'static str,
        /// What is wrong with the value.
        message: String,
    },
    /// A document is not of the form it was read as: not JSON, a key
    /// missing or of another type.
    #[error("not a {form} of deduxit's wire form: {message}")]
    #[non_exhaustive]
    Json {
        /// The form read: `sequent`, `proof`, …
        form: &'static str,
        /// What was wrong, as the reader says it.
        message: String,
    },
    /// A document is of a wire level above the one this build reads.
    #[error("the {form} is of wire level {found}, and this build reads levels up to {supported}")]
    #[non_exhaustive]
    Version {
        /// The form read.
        form: &'static str,
        /// The document's `version`.
        found: u64,
        /// The highest level this build reads, [`wire::LEVEL`](crate::wire::LEVEL).
        supported: u32,
    },
    /// An index of a value read names nothing: it is not below the length
    /// of its space.
    #[error("{}", out_of_bounds(*.space, *.index, *.len))]
    #[non_exhaustive]
    IndexOutOfBounds {
        /// What the index names.
        space: Space,
        /// The index.
        index: usize,
        /// How many there are.
        len: usize,
    },
    /// A term or a proof node names a part that does not come before it,
    /// where every part must precede what uses it.
    #[error("{}", not_topological(*.space, *.index, *.parent))]
    #[non_exhaustive]
    NotTopological {
        /// What the indices name.
        space: Space,
        /// The part named.
        index: usize,
        /// The one that names it.
        parent: usize,
    },
    /// A sequent says more of its root formulas stand left of `⊢`
    /// (`antecedents`) than it has (`roots`).
    #[error(
        "the sequent has {} left of ⊢ but {} in all",
        counted(*.antecedents, "formula", "formulas"),
        counted(*.roots, "formula", "formulas")
    )]
    #[non_exhaustive]
    Antecedents {
        /// How many root formulas the sequent says stand left of `⊢`.
        antecedents: usize,
        /// How many root formulas it has.
        roots: usize,
    },
    /// A cut formula was given as a sequent of `formulas` root formulas,
    /// or with cut formulas of its own, where one formula is the cut's.
    #[error(
        "a cut formula is one formula, not {}",
        counted(*.formulas, "formula", "formulas")
    )]
    #[non_exhaustive]
    CutFormula {
        /// How many root formulas the sequent given has.
        formulas: usize,
    },
    /// An atom name read from a file or given to a constructor is no
    /// identifier of the text syntax, or is one of its keywords or a word
    /// reserved for a later version of it, so that the sequent written as
    /// text would not read back as itself.
    #[error(
        "the atom name {name:?} {}",
        crate::linear::sequents::name::fault(name)
    )]
    #[non_exhaustive]
    AtomName {
        /// The name.
        name: String,
    },
    /// A symbol of a sequent's first-order tables cannot be one, as the
    /// fault says: listed twice, used with another number of arguments
    /// than its arity, or a predicate and a function symbol at once.
    #[error("the symbol {name:?} {fault}")]
    #[non_exhaustive]
    Symbol {
        /// The symbol's name.
        name: String,
        /// What is wrong with it.
        fault: SymbolFault,
    },
    /// A root or a cut formula of a sequent holds a bound variable that no
    /// binder of the formula binds: every formula of a sequent is closed.
    #[error("term {term} holds a bound variable no binder of it binds")]
    #[non_exhaustive]
    LooseVariable {
        /// The arena index of the root or cut formula.
        term: usize,
    },
    /// The table of predicates of a sequent read from JSON has another
    /// length than its table of atoms, where the two must be parallel.
    #[error("{predicates} predicates for {atoms} atoms: every atom has its predicate, or none has")]
    #[non_exhaustive]
    Predicates {
        /// The number of predicate entries.
        predicates: usize,
        /// The number of atoms.
        atoms: usize,
    },
    /// The parts of an interactive proof read back do not fit together, as
    /// the reason says.
    ///
    /// Needs the cargo feature `interactive`.
    #[cfg(feature = "interactive")]
    #[error("not a proof in progress: {reason}")]
    #[non_exhaustive]
    InconsistentSession {
        /// What does not fit.
        reason: &'static str,
    },
    /// A proof does not prove its conclusion, or its check was refused.
    #[error("{}", check_message(.0))]
    Check(CheckError),
    /// A disproof's refutation does not hold, or rests on the search and
    /// has no check ([`Disproof::check`](crate::linear::Disproof::check)).
    #[error("{0}")]
    Refutation(crate::linear::search::RefutationFault),
    /// A list of links is not a proof structure, or a structure is not a
    /// proof net.
    #[error("not a proof net: {0}")]
    Net(Box<NetError>),
    /// A step of an interactive proof does not apply as asked.
    ///
    /// Needs the cargo feature `interactive`.
    #[cfg(feature = "interactive")]
    #[error(transparent)]
    Step(#[from] crate::linear::proofs::StepError),
    /// A step of a proof in progress of an ordinary sequent does not apply
    /// as asked.
    ///
    /// Needs the cargo feature `interactive`.
    #[cfg(feature = "interactive")]
    #[error(transparent)]
    OrdinaryStep(#[from] crate::ordinary::StepError),
    /// An interactive proof still has this many open goals, so there is no
    /// proof term to make of it yet.
    ///
    /// Needs the cargo feature `interactive`.
    #[cfg(feature = "interactive")]
    #[error(
        "the proof is not finished: {}",
        if *.count == 1 { "1 goal is open".to_owned() } else { format!("{} goals are open", .count) }
    )]
    #[non_exhaustive]
    OpenGoals {
        /// How many goals are open.
        count: usize,
    },
    /// A proof given to an interactive proof to close a goal is over
    /// another sequent than the session's, whose goals name occurrences of
    /// the session's own.
    ///
    /// Needs the cargo feature `interactive`.
    #[cfg(feature = "interactive")]
    #[error("the proof is over another sequent than the session's")]
    ForeignProof,
    /// A proof given to close a goal of a session concludes another goal.
    ///
    /// Needs the cargo feature `interactive`.
    #[cfg(feature = "interactive")]
    #[error("the proof concludes another goal than the one it is to close")]
    GoalMismatch,
    /// A proof of a goal, given where a proof of the sequent is needed: a
    /// proof of a goal is checked against the goal, so it is no wrong
    /// proof, only not one of the sequent.
    #[error("the proof concludes a goal, not the sequent")]
    GoalProof,
    /// A proof carried over to a goal ([`Proof::onto`](crate::linear::proofs::Proof::onto))
    /// concludes other formulas than the goal holds, beyond their order.
    #[error(
        "the proof's conclusions are not the goal's formulas: {} only in the proof, {} only in the goal",
        listed(proof),
        listed(goal)
    )]
    #[non_exhaustive]
    SequentMismatch {
        /// The formulas the proof concludes that no formula of the goal
        /// matches, as the sequent writes them.
        proof: Vec<String>,
        /// The goal's formulas that no conclusion of the proof matches.
        goal: Vec<String>,
    },
    /// The mode is intuitionistic and the sequent has no intuitionistic
    /// reading. The message names occurrences by id;
    /// [`ShapeError::describe`] names them by formula.
    #[error("not an intuitionistic sequent: {0}")]
    NotIntuitionistic(ShapeError),
    /// Mix was asked for in intuitionistic mode, where it has no form: a
    /// premise of a Mix would have no goal.
    #[error("Mix has no intuitionistic form: a premise of a Mix would have no goal")]
    IntuitionisticMix,
    /// An ordered mode was asked for with weakening or Mix, which no
    /// calculus here combines with the order: they would let a formula,
    /// or a whole premise, stand anywhere in the order.
    #[error("{mode} mode has no calculus: an ordered mode takes neither weakening nor Mix")]
    #[non_exhaustive]
    OrderedMode {
        /// The mode asked for.
        mode: Mode,
    },
    /// A sequent searched in an ordered mode lies beyond unit-free MLL,
    /// the fragment the ordered calculus is decided in.
    #[error("{mode} mode decides unit-free MLL, and the sequent lies in {fragment}")]
    #[non_exhaustive]
    OrderedFragment {
        /// The sequent's fragment.
        fragment: Fragment,
        /// The ordered mode.
        mode: Mode,
    },
    /// An intuitionistic goal has this many formulas on the right of `⊢`,
    /// where a sequent of intuitionistic linear logic has exactly one.
    #[error("an intuitionistic goal has {count} formulas on the right of ⊢ instead of one")]
    #[non_exhaustive]
    GoalOutputs {
        /// How many formulas stand right of `⊢`.
        count: usize,
    },
    /// An intuitionistic or minimal sequent has more than one formula
    /// right of `⊢`.
    #[error("an intuitionistic sequent has at most one formula right of ⊢, not {count}")]
    #[non_exhaustive]
    Succedents {
        /// How many formulas stand right of `⊢`.
        count: usize,
    },
    /// The sequent uses connectives outside the fragment the search options
    /// assert.
    #[error("the sequent lies in {detected}, outside the asserted fragment {asserted}")]
    #[non_exhaustive]
    FragmentMismatch {
        /// The fragment the options assert.
        asserted: Fragment,
        /// The fragment the sequent was detected to lie in.
        detected: Fragment,
    },
    /// The translation does not decide the logic: the affine one decides
    /// classical logic, the others intuitionistic and minimal logic.
    #[error("the {translation} translation does not decide {logic} logic")]
    #[non_exhaustive]
    Translation {
        /// The translation.
        translation: crate::ordinary::Translation,
        /// The logic.
        logic: crate::ordinary::Logic,
    },
    /// No engine handles the fragment in the mode yet.
    #[error("no engine for {fragment} in {mode} mode yet")]
    #[non_exhaustive]
    NoEngine {
        /// The fragment the search was asked for.
        fragment: Fragment,
        /// The mode the search was asked for.
        mode: Mode,
    },
    /// The engine the options force does not take the goal, for the
    /// reason given: beyond its fragment, outside its modes, not the
    /// sequent itself, or not of its shape.
    #[error("{}", .because.explained(*.engine))]
    #[non_exhaustive]
    EngineRefused {
        /// The engine the options force.
        engine: Engine,
        /// Why it does not take the goal.
        because: NotTaken,
    },
    /// The output has no form for the derivation; nothing was written.
    ///
    /// Needs the cargo feature `rocq`.
    #[cfg(feature = "rocq")]
    #[error(transparent)]
    Unsupported(#[from] crate::export::rocq::Unsupported),
    /// A bound, set or default, or the caller's stop refused the call
    /// before it had an answer; lifting the bound may answer.
    #[error("{0}")]
    Refused(Refusal),
    /// The threads of a parallel search could not be started.
    ///
    /// Needs the cargo feature `parallel`.
    #[cfg(feature = "parallel")]
    #[error("cannot start {threads} search threads: {message}")]
    #[non_exhaustive]
    ThreadPool {
        /// How many threads were asked for.
        threads: usize,
        /// Why they could not be started.
        message: String,
    },
    /// The writer an output went to failed.
    #[error("the writer failed")]
    WriteFailed,
    /// The text given to a renderer is not an SVG document it reads.
    ///
    /// Needs one of the cargo features `png` or `pdf`.
    #[cfg(any(feature = "png", feature = "pdf"))]
    #[error("not an SVG document the renderer reads: {message}")]
    #[non_exhaustive]
    NotSvg {
        /// What the reader of SVG said.
        message: String,
    },
    /// The renderer failed on a document it read, or the document does
    /// not conform to the standard asked for.
    ///
    /// Needs one of the cargo features `png` or `pdf`.
    #[cfg(any(feature = "png", feature = "pdf"))]
    #[error("the renderer failed: {message}")]
    #[non_exhaustive]
    RenderFailed {
        /// What the renderer said.
        message: String,
    },
    /// A PDF/A document needs the date it was made, and none was given.
    ///
    /// Needs the cargo feature `pdf`.
    #[cfg(feature = "pdf")]
    #[error("a PDF/A document needs the date it was made: give pdf::Options::date")]
    NoDate,
    /// A step of cut elimination was asked of a node that is no cut, or of
    /// a proof without one.
    #[error("{}", match .node {
        Some(node) => format!("node {node} is no cut"),
        None => "the proof has no cut".to_owned(),
    })]
    #[non_exhaustive]
    NoCut {
        /// The node named, or `None` where the strategy found no cut.
        node: Option<u32>,
    },
    /// The checker refused the proof a step of cut elimination made: a
    /// defect of this crate, which never returns such a proof.
    #[error("a step of cut elimination made a proof the checker refuses: {0}")]
    Reduction(Box<CheckError>),
    /// The checker rejected the proof a search found: a defect of the
    /// engine that found it, and no verdict on the sequent.
    #[error("{}{}", describe::REJECTED, .0)]
    Rejected(Box<CheckError>),
    /// A proof or a derivation has no lambda-term, for the reason given:
    /// a proof of classical logic, with Mix, of an ordered calculus, with
    /// quantifiers or with open goals ([`Derivation::term`](crate::linear::Derivation::term)).
    #[error("the proof has no lambda-term: {reason}")]
    #[non_exhaustive]
    NoTerm {
        /// Why.
        reason: crate::lambda::NoTerm,
    },
    /// A derivation read back from a linear proof is not one of LK or LJ,
    /// for the reason given: a defect of this crate.
    #[error("the proof read back is not a derivation of {calculus}: {reason}")]
    #[non_exhaustive]
    ReadBack {
        /// LK or LJ.
        calculus: &'static str,
        /// What is wrong, and at which inference.
        reason: String,
    },
}

/// What sort of failure an [`Error`](enum@Error) is.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(
    feature = "serialize",
    derive(serde::Serialize),
    serde(rename_all = "snake_case")
)]
pub enum ErrorKind {
    /// The input is not what it says: no sequent, indices that do not fit.
    Malformed,
    /// A verdict: the proof, net, step or session is not what it claims.
    Invalid,
    /// No verdict: outside what this build, engine, kernel or reader does.
    Unsupported,
    /// No verdict: a bound, set or default, refused the call; lifting it
    /// may answer.
    Limit,
    /// No verdict: the caller's stop ended the call.
    Stopped,
    /// The environment failed: threads, the writer, the renderer.
    Failed,
    /// A check of the library's own result failed: a defect to report.
    Defect,
}

impl ErrorKind {
    /// Returns whether the call was refused without a verdict: neither the
    /// input nor a claim about it is at fault.
    pub const fn is_refusal(self) -> bool {
        matches!(self, Self::Unsupported | Self::Limit | Self::Stopped)
    }

    /// Returns the kind's name, as the wire form writes it.
    pub const fn name(self) -> &'static str {
        match self {
            Self::Malformed => "malformed",
            Self::Invalid => "invalid",
            Self::Unsupported => "unsupported",
            Self::Limit => "limit",
            Self::Stopped => "stopped",
            Self::Failed => "failed",
            Self::Defect => "defect",
        }
    }
}

impl std::fmt::Display for ErrorKind {
    /// Writes the kind's name.
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.name())
    }
}

/// Returns formulas joined by commas, or "nothing" for none: a side of a
/// [`Error::SequentMismatch`].
fn listed(formulas: &[String]) -> String {
    if formulas.is_empty() {
        "nothing".to_owned()
    } else {
        formulas.join(", ")
    }
}

impl Error {
    /// Every code an error of this crate may have.
    pub const CODES: &'static [&'static str] = &[
        "parse",
        "lltp",
        "spec",
        "tptp",
        "several_conjectures",
        "unknown_name",
        "family_size",
        "invalid_option",
        "json",
        "unsupported_version",
        "index_out_of_bounds",
        "not_topological",
        "antecedents",
        "cut_formula",
        "atom_name",
        "inconsistent_session",
        "invalid_proof",
        "invalid_refutation",
        "uncertified",
        "invalid_net",
        "no_nets",
        "step",
        "open_goals",
        "foreign_proof",
        "goal_mismatch",
        "goal_proof",
        "sequent_mismatch",
        "not_intuitionistic",
        "intuitionistic_mix",
        "ordered_mode",
        "symbol",
        "loose_variable",
        "predicates",
        "ordered_fragment",
        "goal_outputs",
        "succedents",
        "fragment_mismatch",
        "translation",
        "no_engine",
        "engine_refused",
        "no_certificate",
        "stopped",
        "memory_limit",
        "too_many_occurrences",
        "too_many_terms",
        "output_too_large",
        "work_limit",
        "too_many_pixels",
        "elimination_limit",
        "index_limit",
        "thread_pool",
        "write_failed",
        "not_svg",
        "render_failed",
        "no_date",
        "rejected",
        "read_back",
        "no_term",
        "no_cut",
        "reduction_rejected",
    ];

    /// Returns what sort of failure this is; a wrapped error answers with
    /// its own kind, so a refused check is a refusal.
    pub fn kind(&self) -> ErrorKind {
        use ErrorKind::*;
        match self {
            #[cfg(feature = "parse")]
            Self::Parse(_)
            | Self::Lltp { .. }
            | Self::Spec { .. }
            | Self::Tptp { .. }
            | Self::SeveralConjectures { .. } => Malformed,
            Self::UnknownName { .. } | Self::InvalidOption { .. } | Self::Json { .. } => Malformed,
            #[cfg(feature = "parse")]
            Self::FamilySize { .. } => Malformed,
            Self::Version { .. } => Unsupported,
            Self::IndexOutOfBounds { .. }
            | Self::NotTopological { .. }
            | Self::Antecedents { .. }
            | Self::CutFormula { .. }
            | Self::AtomName { .. }
            | Self::Symbol { .. }
            | Self::LooseVariable { .. }
            | Self::Predicates { .. } => Malformed,
            #[cfg(feature = "interactive")]
            Self::InconsistentSession { .. } => Malformed,
            Self::Check(CheckError::Invalid(_)) => Invalid,
            Self::Check(CheckError::Refused(refused)) => refusal_kind(&refused.refusal),
            Self::Refutation(crate::linear::search::RefutationFault::Uncertified { .. }) => {
                Unsupported
            }
            Self::Refutation(_) => Invalid,
            Self::Net(error) => error.kind(),
            #[cfg(feature = "interactive")]
            Self::Step(_)
            | Self::OrdinaryStep(_)
            | Self::OpenGoals { .. }
            | Self::ForeignProof
            | Self::GoalMismatch => Invalid,
            Self::GoalProof => Unsupported,
            Self::SequentMismatch { .. } => Invalid,
            Self::NotIntuitionistic(_)
            | Self::IntuitionisticMix
            | Self::OrderedMode { .. }
            | Self::OrderedFragment { .. }
            | Self::GoalOutputs { .. }
            | Self::Succedents { .. }
            | Self::FragmentMismatch { .. }
            | Self::Translation { .. }
            | Self::NoEngine { .. }
            | Self::EngineRefused { .. } => Unsupported,
            #[cfg(feature = "rocq")]
            Self::Unsupported(_) => Unsupported,
            Self::Refused(refusal) => refusal_kind(refusal),
            #[cfg(feature = "parallel")]
            Self::ThreadPool { .. } => Failed,
            Self::WriteFailed => Failed,
            #[cfg(any(feature = "png", feature = "pdf"))]
            Self::NotSvg { .. } => Malformed,
            #[cfg(any(feature = "png", feature = "pdf"))]
            Self::RenderFailed { .. } => Failed,
            #[cfg(feature = "pdf")]
            Self::NoDate => Malformed,
            Self::Rejected(_) | Self::ReadBack { .. } | Self::Reduction(_) => Defect,
            Self::NoCut { .. } => Unsupported,
            Self::NoTerm { .. } => Unsupported,
        }
    }

    /// Returns the stable reason a program branches on, never the English
    /// text: one of [`CODES`](Self::CODES).
    pub fn code(&self) -> &'static str {
        match self {
            #[cfg(feature = "parse")]
            Self::Parse(_) => "parse",
            #[cfg(feature = "parse")]
            Self::Lltp { .. } => "lltp",
            #[cfg(feature = "parse")]
            Self::Spec { .. } => "spec",
            #[cfg(feature = "parse")]
            Self::Tptp { .. } => "tptp",
            #[cfg(feature = "parse")]
            Self::SeveralConjectures { .. } => "several_conjectures",
            Self::UnknownName { .. } => "unknown_name",
            #[cfg(feature = "parse")]
            Self::FamilySize { .. } => "family_size",
            Self::InvalidOption { .. } => "invalid_option",
            Self::Json { .. } => "json",
            Self::Version { .. } => "unsupported_version",
            Self::IndexOutOfBounds { .. } => "index_out_of_bounds",
            Self::NotTopological { .. } => "not_topological",
            Self::Antecedents { .. } => "antecedents",
            Self::CutFormula { .. } => "cut_formula",
            Self::AtomName { .. } => "atom_name",
            Self::Symbol { .. } => "symbol",
            Self::LooseVariable { .. } => "loose_variable",
            Self::Predicates { .. } => "predicates",
            #[cfg(feature = "interactive")]
            Self::InconsistentSession { .. } => "inconsistent_session",
            Self::Check(CheckError::Invalid(_)) => "invalid_proof",
            Self::Check(CheckError::Refused(refused)) => refused.refusal.code(),
            Self::Refutation(crate::linear::search::RefutationFault::Uncertified { .. }) => {
                "uncertified"
            }
            Self::Refutation(_) => "invalid_refutation",
            Self::Net(error) => error.code(),
            #[cfg(feature = "interactive")]
            Self::Step(_) | Self::OrdinaryStep(_) => "step",
            #[cfg(feature = "interactive")]
            Self::OpenGoals { .. } => "open_goals",
            #[cfg(feature = "interactive")]
            Self::ForeignProof => "foreign_proof",
            #[cfg(feature = "interactive")]
            Self::GoalMismatch => "goal_mismatch",
            Self::GoalProof => "goal_proof",
            Self::SequentMismatch { .. } => "sequent_mismatch",
            Self::NotIntuitionistic(_) => "not_intuitionistic",
            Self::IntuitionisticMix => "intuitionistic_mix",
            Self::OrderedMode { .. } => "ordered_mode",
            Self::OrderedFragment { .. } => "ordered_fragment",
            Self::GoalOutputs { .. } => "goal_outputs",
            Self::Succedents { .. } => "succedents",
            Self::FragmentMismatch { .. } => "fragment_mismatch",
            Self::Translation { .. } => "translation",
            Self::NoEngine { .. } => "no_engine",
            Self::EngineRefused { .. } => "engine_refused",
            #[cfg(feature = "rocq")]
            Self::Unsupported(_) => "no_certificate",
            Self::Refused(refusal) => refusal.code(),
            #[cfg(feature = "parallel")]
            Self::ThreadPool { .. } => "thread_pool",
            Self::WriteFailed => "write_failed",
            #[cfg(any(feature = "png", feature = "pdf"))]
            Self::NotSvg { .. } => "not_svg",
            #[cfg(any(feature = "png", feature = "pdf"))]
            Self::RenderFailed { .. } => "render_failed",
            #[cfg(feature = "pdf")]
            Self::NoDate => "no_date",
            Self::Rejected(_) => "rejected",
            Self::ReadBack { .. } => "read_back",
            Self::NoCut { .. } => "no_cut",
            Self::NoTerm { .. } => "no_term",
            Self::Reduction(_) => "reduction_rejected",
        }
    }

    /// Returns the settings key whose bound refused the call, which a front
    /// end maps to its flag: `None` for every error a bound did not cause.
    pub fn setting(&self) -> Option<&'static str> {
        match self {
            Self::Refused(refusal) => refusal.setting(),
            Self::Check(CheckError::Refused(refused)) => refused.refusal.setting(),
            Self::Net(error) => match error.as_ref() {
                NetError::Refused { refusal } => refusal.setting(),
                _ => None,
            },
            _ => None,
        }
    }

    /// Returns whether the call was refused without a verdict, as
    /// [`ErrorKind::is_refusal`] says of the error's kind.
    pub fn is_refusal(&self) -> bool {
        self.kind().is_refusal()
    }
}

/// The kind of an error that a refusal makes.
pub(crate) const fn refusal_kind(refusal: &Refusal) -> ErrorKind {
    match refusal {
        Refusal::Stopped { .. } => ErrorKind::Stopped,
        _ => ErrorKind::Limit,
    }
}

/// Lists names as prose: `a, b or c`.
fn or_list(names: &[&str]) -> String {
    match names.split_last() {
        None => String::new(),
        Some((last, [])) => (*last).to_owned(),
        Some((last, rest)) => format!("{} or {last}", rest.join(", ")),
    }
}

/// The message of an index that names nothing.
fn out_of_bounds(space: Space, index: usize, len: usize) -> String {
    match space {
        Space::Atom => format!(
            "a term refers to atom {index}, but the atom list has {}",
            counted(len, "name", "names")
        ),
        Space::Term => format!(
            "a root formula is term {index}, but the arena has {}",
            counted(len, "term", "terms")
        ),
        Space::Node => format!(
            "a proof refers to node {index}, but it has {}",
            counted(len, "node", "nodes")
        ),
        Space::Occurrence => format!(
            "a proof node refers to occurrence {index}, but the sequent has {}",
            counted(len, "occurrence", "occurrences")
        ),
        _ => format!(
            "an index names {index}, but there {} {}",
            if len == 1 { "is" } else { "are" },
            counted(len, space.singular(), space.plural())
        ),
    }
}

/// Writes a count with the noun that agrees with it: `1 goal`, `2 goals`.
pub(crate) fn counted<N>(count: N, one: &str, many: &str) -> String
where
    N: Copy + std::fmt::Display + TryInto<u64>,
{
    let noun = if count.try_into().ok() == Some(1) {
        one
    } else {
        many
    };
    format!("{count} {noun}")
}

/// The message of a part that names a part after it.
fn not_topological(space: Space, index: usize, parent: usize) -> String {
    match space {
        Space::Node => format!(
            "proof node {parent} has premise {index}, but a premise must come before the nodes \
             that use it"
        ),
        _ => format!(
            "term {parent} refers to term {index}, but a subterm must come before the terms that \
             use it"
        ),
    }
}

/// The message of a checker's error: a fault of the proof says so, a
/// refusal is its own.
fn check_message(error: &CheckError) -> String {
    match error {
        CheckError::Invalid(_) => format!("{INVALID_PROOF}{error}"),
        CheckError::Refused(_) => error.to_string(),
    }
}

impl From<CheckError> for Error {
    /// Wraps the checker's error, a fault and a refusal alike.
    fn from(error: CheckError) -> Self {
        Self::Check(error)
    }
}

impl From<NetError> for Error {
    /// Wraps the structure's error.
    fn from(error: NetError) -> Self {
        Self::Net(Box::new(error))
    }
}

impl From<ShapeError> for Error {
    /// Wraps why the sequent has no intuitionistic reading.
    fn from(error: ShapeError) -> Self {
        Self::NotIntuitionistic(error)
    }
}

impl From<Refusal> for Error {
    /// Wraps the refusal.
    fn from(refusal: Refusal) -> Self {
        Self::Refused(refusal)
    }
}

impl From<std::fmt::Error> for Error {
    /// The writer failed.
    fn from(_: std::fmt::Error) -> Self {
        Self::WriteFailed
    }
}

#[cfg(feature = "parse")]
impl From<ParseError> for Error {
    /// Wraps where and why the text is not a sequent.
    fn from(error: ParseError) -> Self {
        Self::Parse(Box::new(error))
    }
}

/// What [`Error::Check`] says before the checker's fault.
const INVALID_PROOF: &str = "invalid proof: ";

/// Errors stay small enough to pass by value in a `Result`.
const _: () = assert!(size_of::<Error>() <= 64);

/// Errors cross threads and outlive the call that made them.
const _: fn() = || {
    /// Compiles only for a type that is `Send`, `Sync` and `'static`.
    const fn shared<T: Send + Sync + 'static>() {}
    shared::<Error>();
};

#[cfg(test)]
mod tests {
    use super::*;
    use std::collections::BTreeSet;

    /// One error of every variant, and of every code a wrapped type
    /// gives.
    fn samples() -> Vec<Error> {
        use crate::limits::Phase;
        use crate::linear::occurrences::{Member, OccId};
        use crate::linear::proofs::{Fault, Invalid, Node, NodeId, Refused};
        let refusals = [
            Refusal::Stopped {
                phase: Phase::Search,
            },
            Refusal::Memory {
                phase: Phase::Search,
                limit_bytes: 1,
                needed_bytes: None,
            },
            Refusal::Occurrences {
                occurrences: 2,
                limit: 1,
            },
            Refusal::Terms { terms: 2, limit: 1 },
            Refusal::Output {
                what: "derivation",
                estimate_bytes: 2,
                limit_bytes: 1,
                least_bytes: None,
            },
            Refusal::Work { limit: 1 },
            Refusal::Pixels {
                pixels: 2,
                limit: 1,
            },
            Refusal::Elimination {
                what: crate::limits::Bound::Steps,
                limit: 1,
            },
            Refusal::Index {
                what: Space::Node,
                count: 2,
                most: 1,
            },
        ];
        let invalid = CheckError::Invalid(Box::new(Invalid {
            node: NodeId::new(0),
            rule: Node::One(Member::from(OccId::new(0))),
            premises: Vec::new(),
            fault: Fault::NotDual,
        }));
        let message = String::new;
        let mut samples = vec![
            Error::UnknownName {
                what: "mode",
                name: "x".into(),
                known: &[],
            },
            Error::InvalidOption {
                key: "typst",
                message: message(),
            },
            Error::Json {
                form: "sequent",
                message: message(),
            },
            Error::Version {
                form: "sequent",
                found: 2,
                supported: 1,
            },
            Error::IndexOutOfBounds {
                space: Space::Term,
                index: 1,
                len: 1,
            },
            Error::NotTopological {
                space: Space::Term,
                index: 1,
                parent: 0,
            },
            Error::Antecedents {
                antecedents: 2,
                roots: 1,
            },
            Error::CutFormula { formulas: 2 },
            Error::AtomName { name: "par".into() },
            Error::Symbol {
                name: "p".into(),
                fault: SymbolFault::Role,
            },
            Error::Predicates {
                predicates: 1,
                atoms: 2,
            },
            Error::LooseVariable { term: 3 },
            Error::Check(invalid.clone()),
            Error::Check(CheckError::Refused(Refused {
                node: NodeId::new(0),
                refusal: refusals[0].clone(),
            })),
            Error::Refutation(crate::linear::search::RefutationFault::Satisfied),
            Error::Refutation(crate::linear::search::RefutationFault::Uncertified {
                kind: "exhausted",
            }),
            Error::GoalProof,
            Error::SequentMismatch {
                proof: vec!["A ⊗ B".into()],
                goal: Vec::new(),
            },
            Error::NotIntuitionistic(ShapeError::NoGoal),
            Error::IntuitionisticMix,
            Error::OrderedMode {
                mode: Mode::CYCLIC.with_mix(),
            },
            Error::OrderedFragment {
                fragment: Fragment::MALL,
                mode: Mode::CYCLIC,
            },
            Error::GoalOutputs { count: 2 },
            Error::Succedents { count: 2 },
            Error::FragmentMismatch {
                asserted: Fragment::MLL,
                detected: Fragment::LL,
            },
            Error::Translation {
                translation: crate::ordinary::Translation::Affine,
                logic: crate::ordinary::Logic::Intuitionistic,
            },
            Error::NoEngine {
                fragment: Fragment::LL,
                mode: Mode::CLASSICAL,
            },
            Error::EngineRefused {
                engine: Engine::Net,
                because: NotTaken::Goal,
            },
            Error::WriteFailed,
            Error::Rejected(Box::new(invalid.clone())),
            Error::Reduction(Box::new(invalid)),
            Error::NoCut { node: Some(3) },
            Error::NoTerm {
                reason: crate::lambda::NoTerm::Classical,
            },
            Error::ReadBack {
                calculus: "LK",
                reason: message(),
            },
        ];
        let vertex = crate::linear::nets::VertexId::new(0);
        let nets = [
            NetError::NoVertex {
                vertex: 1,
                vertices: 1,
            },
            NetError::NotLiteral { vertex },
            NetError::NotDual {
                x: vertex,
                y: vertex,
            },
            NetError::LinkedTwice { vertex },
            NetError::Unlinked { vertex },
            NetError::Empty,
            NetError::SwitchingCycle {
                cycle: vec![vertex],
            },
            NetError::Disconnected {
                parts: vec![vec![vertex]],
            },
            NetError::DirectedCycle {
                cycle: vec![vertex],
            },
            NetError::NoDominator {
                implication: vertex,
                path: vec![vertex],
            },
            NetError::Crossing {
                links: [(vertex, vertex), (vertex, vertex)],
            },
            NetError::NotIntuitionistic {
                shape: ShapeError::NoGoal,
            },
            NetError::Fragment {
                fragment: Fragment::LL,
            },
            NetError::Mode {
                mode: Mode::CLASSICAL.with_affine(),
            },
            NetError::Rule {
                node: NodeId::new(0),
                rule: "wk",
            },
            NetError::Placement {
                vertex,
                fault: crate::linear::nets::Placement::Premise,
            },
            NetError::Unattached { vertex },
            NetError::InBox {
                door: vertex,
                error: Box::new(NetError::Empty),
            },
            NetError::NotMell {
                fragment: Fragment::LL,
                mode: Mode::INTUITIONISTIC,
            },
            NetError::NoCut {
                vertex: Some(vertex),
            },
            NetError::Reduction {
                error: Box::new(NetError::Empty),
            },
            NetError::Refused {
                refusal: refusals[1].clone(),
            },
        ];
        samples.extend(nets.into_iter().map(|error| Error::Net(Box::new(error))));
        samples.extend(refusals.into_iter().map(Error::Refused));
        #[cfg(feature = "parse")]
        samples.extend([
            Error::Parse(Box::new(ParseError::spanning("(", 1..1, &["a formula"]))),
            Error::Lltp { message: message() },
            Error::Spec { message: message() },
            Error::Tptp { message: message() },
            Error::SeveralConjectures { second: message() },
            Error::FamilySize {
                family: "chain",
                size: 0,
                least: 1,
                powers_of_two: false,
            },
        ]);
        #[cfg(feature = "interactive")]
        samples.extend([
            Error::InconsistentSession { reason: "" },
            Error::Step(crate::linear::proofs::StepError::NoGoal {
                goal: crate::linear::proofs::interactive::GoalId::new(0),
            }),
            Error::OpenGoals { count: 1 },
            Error::ForeignProof,
            Error::GoalMismatch,
        ]);
        #[cfg(feature = "rocq")]
        samples.push(Error::Unsupported(crate::export::rocq::Unsupported::Mix));
        #[cfg(feature = "parallel")]
        samples.push(Error::ThreadPool {
            threads: 2,
            message: message(),
        });
        #[cfg(any(feature = "png", feature = "pdf"))]
        samples.extend([
            Error::NotSvg { message: message() },
            Error::RenderFailed { message: message() },
        ]);
        #[cfg(feature = "pdf")]
        samples.push(Error::NoDate);
        samples
    }

    /// Names every variant without a wildcard, and those of the wrapped
    /// refusals and net errors, so that a variant added later fails to
    /// compile here, next to the samples where it needs one.
    fn variant(error: &Error) {
        match error {
            Error::Net(net) => match net.as_ref() {
                NetError::Refused { refusal } => refused(refusal),
                NetError::NoVertex { .. }
                | NetError::NotLiteral { .. }
                | NetError::NotDual { .. }
                | NetError::LinkedTwice { .. }
                | NetError::Unlinked { .. }
                | NetError::Empty
                | NetError::SwitchingCycle { .. }
                | NetError::Disconnected { .. }
                | NetError::DirectedCycle { .. }
                | NetError::NoDominator { .. }
                | NetError::Crossing { .. }
                | NetError::NotIntuitionistic { .. }
                | NetError::Fragment { .. }
                | NetError::Mode { .. }
                | NetError::Rule { .. }
                | NetError::Placement { .. }
                | NetError::Unattached { .. }
                | NetError::InBox { .. }
                | NetError::NotMell { .. }
                | NetError::NoCut { .. }
                | NetError::Reduction { .. } => {}
            },
            Error::Refused(refusal) => refused(refusal),
            #[cfg(feature = "parse")]
            Error::Parse(_)
            | Error::Lltp { .. }
            | Error::Spec { .. }
            | Error::Tptp { .. }
            | Error::SeveralConjectures { .. }
            | Error::FamilySize { .. } => {}
            #[cfg(feature = "interactive")]
            Error::InconsistentSession { .. }
            | Error::Step(_)
            | Error::OrdinaryStep(_)
            | Error::OpenGoals { .. }
            | Error::ForeignProof
            | Error::GoalMismatch => {}
            #[cfg(feature = "rocq")]
            Error::Unsupported(_) => {}
            #[cfg(feature = "parallel")]
            Error::ThreadPool { .. } => {}
            #[cfg(any(feature = "png", feature = "pdf"))]
            Error::NotSvg { .. } | Error::RenderFailed { .. } => {}
            #[cfg(feature = "pdf")]
            Error::NoDate => {}
            Error::UnknownName { .. }
            | Error::InvalidOption { .. }
            | Error::Json { .. }
            | Error::Version { .. }
            | Error::IndexOutOfBounds { .. }
            | Error::NotTopological { .. }
            | Error::Antecedents { .. }
            | Error::CutFormula { .. }
            | Error::AtomName { .. }
            | Error::Symbol { .. }
            | Error::LooseVariable { .. }
            | Error::Predicates { .. }
            | Error::Check(_)
            | Error::Refutation(_)
            | Error::GoalProof
            | Error::SequentMismatch { .. }
            | Error::NotIntuitionistic(_)
            | Error::IntuitionisticMix
            | Error::OrderedMode { .. }
            | Error::OrderedFragment { .. }
            | Error::GoalOutputs { .. }
            | Error::Succedents { .. }
            | Error::FragmentMismatch { .. }
            | Error::Translation { .. }
            | Error::NoEngine { .. }
            | Error::EngineRefused { .. }
            | Error::WriteFailed
            | Error::Rejected(_)
            | Error::ReadBack { .. }
            | Error::NoCut { .. }
            | Error::NoTerm { .. }
            | Error::Reduction(_) => {}
        }
    }

    /// Names every refusal without a wildcard, as [`variant`] names the
    /// errors.
    fn refused(refusal: &Refusal) {
        match refusal {
            Refusal::Stopped { .. }
            | Refusal::Memory { .. }
            | Refusal::Occurrences { .. }
            | Refusal::Terms { .. }
            | Refusal::Output { .. }
            | Refusal::Work { .. }
            | Refusal::Pixels { .. }
            | Refusal::Elimination { .. }
            | Refusal::Index { .. } => {}
        }
    }

    /// `CODES` lists exactly the codes the errors give, once each; a code
    /// of a feature this build lacks is listed without a sample.
    #[test]
    fn the_codes_are_listed() {
        let listed: BTreeSet<&str> = Error::CODES.iter().copied().collect();
        assert_eq!(listed.len(), Error::CODES.len(), "a code listed twice");
        let mut given = BTreeSet::new();
        for error in samples() {
            variant(&error);
            assert!(
                listed.contains(error.code()),
                "{} is not listed",
                error.code()
            );
            given.insert(error.code());
        }
        let parse = ["parse", "lltp", "spec", "tptp", "several_conjectures"];
        let interactive = [
            "inconsistent_session",
            "step",
            "open_goals",
            "foreign_proof",
            "goal_mismatch",
        ];
        let gated = |code: &str| {
            let render = cfg!(any(feature = "png", feature = "pdf"));
            (parse.contains(&code) || code == "family_size") && !cfg!(feature = "parse")
                || interactive.contains(&code) && !cfg!(feature = "interactive")
                || code == "no_certificate" && !cfg!(feature = "rocq")
                || code == "thread_pool" && !cfg!(feature = "parallel")
                || (code == "not_svg" || code == "render_failed") && !render
                || code == "no_date" && !cfg!(feature = "pdf")
        };
        for code in listed.difference(&given) {
            assert!(gated(code), "no error gives {code}");
        }
    }
}