You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
relay: the module doc credits the encoder/decoder pair for a consistency only the pin test holds #1027
//! **A refusal is stored as one byte**, and [`Refusal`] owns both ends of it: [`Refusal`]'s//! `word` encodes a variant exhaustively and `from_word` decodes every byte, so the byte's//! meaning cannot drift from the enum.
The consistency is not held by the compiler; it is held by a test.word() is an exhaustive match over Refusal, so the compiler asks for a byte when a variant is added — but nothing forces the discriminants (None = NO_REFUSAL, QueueFull = QUEUE_FULL, BudgetExhausted = BUDGET_EXHAUSTED) and word()'s arms to agree. Measured during the review: changing const QUEUE_FULL: u8 = 1; to 4compiles, and the only thing that fails is every_refusal_word_is_pinned_to_its_byte (sink.rs:698, reading (0, 4, 2) against (0, 1, 2)).
So "cannot drift" is true of the branch's test suite and false of the type. Two ways to make the sentence honest, and either fixes it:
Say what holds it — "the pin test holds the bytes and word() to each other" — which costs one clause and no code, or
Remove the duplicate encoding: the discriminants and word()'s arms are two statements of one fact, and word() could be derived from the discriminant so only one statement exists.
Filed from job 019-refusal-exhaustive's review; the sentence is new in #1026.
Activity