Repository navigation
docs: cite Rust code by symbol instead of by line number - #1480
Merged
Merged
Conversation
`check_doc_citations.py` resolves `doc/**` and `**/LIFECYCLE.md`, so a `path.rs:NNN` inside a `//`, `///` or `//!` comment was read by no rule at all — not the existence floor, not the drift comparison, not once. The two `SAFETY:` comments justifying `from_utf8_unchecked` in `lib/src/http.rs` and `lib/src/https.rs` are how it surfaced (#1473): both cited a `Method` match arm for `hostname_and_port`, and drifted there with CI green throughout, until #1474 re-pointed them at the function. The population was measured before the form was chosen, at main `19fd5d8c`: 90 citation tokens across 29 files, holding 113 line targets. Sixty-eight of the 90 had drifted from the text they named at the commit that last wrote or re-anchored them, and only 16 still land on a line that is neither a bare delimiter, a blank, nor past end-of-file. The half-life decided it: 43 of those 68 broke on the very NEXT commit that touched the file they point into, the median citation survived ONE such commit and zero days, and 65 of 68 were wrong inside a week. All 18 `h2.rs:NNN` tokens had drifted. Extending the resolver over `**/*.rs` was the alternative, and it was measured rather than argued: switched on at that revision it would have had to reject those 68, plus 14 naming a basename that is ambiguous here — four files are called `h2.rs`, nineteen `mod.rs` — plus two pointing into the `kawa` dependency, which is not in this repository. A gate that fails on most of the population it guards gets bypassed rather than satisfied, which is the argument the script's own header makes about `--all-features`. So `doc/README.md`'s three forms now govern Rust comments too, with one narrowing: the symbol form only, and a comment that means one branch names that branch in words. All 82 citations outside `lib/src/protocol/mux/` are converted, across 25 files, each re-pointed at the symbol recovered by reading the cited file AT THE COMMIT THAT WROTE THE CITATION rather than at HEAD. The rule is also in `CLAUDE.md`'s code-style list. Rewrapping the comments shifted lines in `e2e/src/tests/h2_correctness_tests.rs`, and the drift rule caught two `doc/testing.md` citations pointing into it — the guarded half of exactly the pair #1465 was about. They now name `try_h2_large_gzipped_chunked_drains_fully` and `try_h2_large_chunked_7mb_drains_fully`. Two corrections fell out of recovering intent rather than trusting HEAD: `h2_log_context_tests.rs` named `log_context_lite!` for a line that is inside `log_module_context!` — only the latter renders the bare `MUX-H2` tag the comment claims — and `e2e/src/tests/mod.rs` named two tests by a line holding their `#[serial_test::serial]` attribute. Comments and documentation only; no code, literal, attribute, assertion or test name changed. The eight sites under `lib/src/protocol/mux/` are left for a separate pass to keep this off a module under concurrent change; two of them, into pinned `kawa` 0.7.1, are the one class here where a line number genuinely cannot rot. Refs #1473 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 23, 2026 20:47
This was referenced Sep 24, 2026
ci(doc): forbid a file.rs:NNN citation in a Rust comment, and convert the live ones to symbols
#1493
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
file:linecitations written inside Rust comments drift with no signal — the CI gate reads onlydoc/**and**/LIFECYCLE.md. #1473 framed the fix as a genuine fork: extend the gate to**/*.rs, or stop writing line numbers in Rust comments and cite the symbol instead. This measures the population and takes the second.Comment-only: zero non-comment
.rslines changed.sozu-lib1092, unchanged.The measurement that decided it
90
file:linecitation tokens in Rust comments, across 29 files, naming 113 line targets.h2.rs:NNNtokens in the treeTwo caveats so those numbers are not misread: 22 were unchanged since written, which is not the same as correct — three were
} else {,);and};from birth. "Defensible" means intact and not landing on a bare delimiter, blank line, or past EOF.The number that killed "extend the gate": the deduped day-one failure set is 70 of 90 (78%) — 68 drifted, 14 naming an ambiguous basename (four files are
h2.rs, nineteen aremod.rs), 2 pointing into thekawadependency, 1 blank target. Turning on a check that fails 78 of every 100 citations on its first run produces a gate people bypass rather than satisfy, which the script's own header already argues in another context.A one-commit half-life is not a maintenance problem to tighten. It is a form that does not work.
Not a new convention — an existing one, extended
doc/README.mdalready documents this, and its first rule is exactly symbol citation. It was simply scoped to "these documents". So the change is the scope, not the rule: the convention now covers Rust comments, with the measurements recorded under#citing-code-from-a-rust-comment, the rule alone inCLAUDE.mdas a pointer rather than a restated copy, and aCHANGELOG.mdentry under Changed.82 of 90 converted, across 25 files. Each was re-pointed at the symbol recovered by reading the target at the commit that wrote the citation, not at HEAD — for two-thirds of them HEAD is a different construct entirely.
The conflict resolution is the argument for this change
This branch conflicted with #1477 in
e2e/src/tests/h2_priority_rearm_tests.rs. #1477's side was pure line arithmetic (mod.rs:1402-1423→:1403-1424), derived from the cited line's text — the technique this repository rightly prefers.Both of its renumbered citations are wrong by about 880 lines.
mod.rs:1403-1424sits inready_inner(starts 1349); the real timeout path isMux::timeout_inner(1997), with thetimeout_backendtrace at 2154 and theshould_writedrain loop at 2282-2283.This is not #1477's error. The citation had already drifted into
ready_innerby19fd5d8c, andself.context.now = Instant::now();is a duplicated idiom present in bothready_inner's andtimeout_inner's loops — so tracking the text faithfully landed on the wrong copy. That isdoc/README.md's own #1437 lesson reproduced: a re-anchor preserves the pointer, not the claim.My own symbol was imperfect too:
SessionState::timeoutwas correct at the commit that wrote the citation, but the body has since split into a wrapper at 1079 andMux::timeout_innerat 1997. Resolved toMux::timeout_innerfor all three — strictly better than either side, and verified to hold both claims at04fade63.doc/testing.mdauto-merged, which is where a convergence trap would hide, so it was read rather than trusted: #1477'sh2.rs:5403→:5401on line 676 and two symbol conversions on 680-682, different lines in the same paragraph. Correct.Two semantic corrections, not re-pointing
Worth a reviewer's eye, because these change what the comment says:
h2_log_context_tests.rsnamedlog_context_lite!for a line insidelog_module_context!. Only the latter renders the bareMUX-H2tag with no session block, which is what the comment claims.e2e/src/tests/mod.rsnamed two tests by a line holding their#[serial_test::serial]attribute rather than the test.What is deliberately left
8 sites under
lib/src/protocol/mux/, because that directory is being rewritten by the write-path inversion (#1479) and converting them now would conflict. Ready-to-paste replacements are recorded for the follow-up.Two of those are the one principled exception in the whole population:
stream.rs's citations into a pinnedkawaversion. A line number into a pinned dependency cannot drift, and both are correct today.A gate rule rejecting
PATH:[0-9]+in*.rscomments belongs incheck_doc_citations.py, which #1478 is currently changing. It would start green outsidemux/at this HEAD. Sequenced after both land rather than written here as a parallel script.Verified
The gate caught one of my own mistakes mid-work: rewrapping shifted lines in
h2_correctness_tests.rs, and--baseflagged twodoc/testing.mdcitations pointing into it — the guarded half of exactly the pair #1465 was about. Fixed by naming the two tests.One item stays unverified and is stated rather than glossed:
fuzz/fuzz_targets/fuzz_command_channel.rsis comment-edited, butfuzzis a separate workspace, so neither the battery norcargo fmt --allreaches it.rustfmt --checkexits 1 on that file byte-identically on the pre-change baseline (an import-ordering artifact in auseblock untouched here), which proves it still parses; with zero non-comment lines changed, a comment-only edit that parses cannot alter compilation. To close it fully:cd fuzz && cargo +nightly fuzz build fuzz_command_channel.Refs #1473