Repository navigation
Description
Two SAFETY: comments justifying from_utf8_unchecked cite a line that is not the function they name, and the citation CI gate cannot see them because it only reads doc/** and **/LIFECYCLE.md.
The two sites
lib/src/http.rs:849 and lib/src/https.rs:1242 carry the same comment:
// SAFETY: `hostname` was just produced by `hostname_and_port` (see
// `lib/src/protocol/kawa_h1/parser.rs:133`), which only accepts
// bytes matching `is_hostname_char` (alphanumeric, `-`, `.`, plus
// `_` under the tolerant-http1-parser feature). All accepted
// bytes are ASCII (≤ 0x7F), so the slice is valid single-byte UTF-8.On c9dd662a, parser.rs:133 is:
Self::Head => "HEAD",— a match arm inside AsRef<str> for Method. hostname_and_port is at parser.rs:184.
Why this is worth fixing rather than leaving
The argument these comments make is the only thing standing between from_utf8_unchecked and undefined behaviour: the claim is that every byte hostname_and_port accepts is ASCII, so the slice is valid UTF-8. A reader auditing that unsafe block follows the citation to verify the claim, lands on an unrelated Method match arm, and has to go find the real function by hand — at which point the comment has cost them confidence rather than given it.
The substantive claim itself is correct at parser.rs:184; is_hostname_char does restrict to ASCII. Only the pointer is wrong. That is the dangerous shape: a true justification with a broken proof path degrades silently instead of failing, because nothing re-reads it until someone is already suspicious.
Why CI did not catch it
.github/scripts/check_doc_citations.py resolves citations under doc/** and **/LIFECYCLE.md. A file:line citation inside a Rust comment is outside its scope entirely — so these two drifted with no signal, and any future line shift in parser.rs moves them further without a gate firing.
That is the general gap, not specific to these two: git grep -nE '(lib|command|bin)/src/[a-z_/]+\.rs:[0-9]+' -- '*.rs' finds every Rust-comment citation in the tree, and none of them is checked by anything.
The fix
Two parts, and the second is the one that matters:
- Repoint both comments at
parser.rs:184. - Decide whether Rust-comment citations should be in the gate's scope at all. Extending the resolver to
**/*.rswould cover them, but it also widens rule 2 (drift) across the whole codebase, where line shifts are constant and legitimate — so the honest options are to extend the gate, or to stop writing line numbers in Rust comments and cite the symbol by name instead. Citinghostname_and_portwithout a line number would have been immune to this and costs a reader onegit grep.
My inclination is (2)-by-symbol: a line number in a comment is a pointer with no owner, and this issue is what that costs.
Found while reviewing an unrelated change to Method::new (#1451); the branch there shifted these citations two further lines without touching them, which is how the staleness surfaced.
Activity
refactor(mux-h2): move one write pass's locals into H2WritePass
refactor(mux-h2): move one write pass's locals into H2WritePass
refactor(mux-h2): move one write pass's locals into H2WritePass (#1477)
docs(citations): cite a symbol, not a line, from a Rust comment
docs(citations): cite a symbol, not a line, from a Rust comment (#1480)
ci(doc): forbid a file.rs:NNN citation written in a Rust comment
ci(doc): forbid a file.rs:NNN citation written in a Rust comment (#1493)
FlorentinDUBOIS commentedon Sep 24, 2026
Closed by #1493 (
6172929e).Part 1 — repointing the two
SAFETYcomments — was already done by #1480: both now citelib/src/protocol/kawa_h1/parser.rsby path withhostname_and_portnamed in prose, and no line number.Part 2 was the part that mattered, and this issue's own inclination is what shipped:
check_doc_citations.pynow forbidsfile.rs:NNNwritten in a Rust comment rather than resolving it, which avoids widening the drift rule across a codebase where line shifts are constant and legitimate. Verified live onmain:--root .exit 0,--self-testexit 0, and the deliberately-broken fixture tree still exits 1 asci.ymlasserts.The population was 8, not the 4 a prefix grep finds
Worth recording, because it is this issue's own thesis recurring. Grepping for
(lib|command|bin|e2e)/src/…\.rs:[0-9]+finds four. Driving the script's ownPATHregex finds eight — the extra live one being unbackticked and sibling-relative:// Mirror of h1.rs:361-368 for the H2-backend → H2-frontendA prefix-keyed extractor walks straight past it. That is the #1459 shape, and it is why the new rule fires through rule 1's own
resolve_path(sibling-first) rather than a fresh pattern: the rule and the resolver cannot disagree about which file a citation names.Three of the four prefix-visible citations were wrong, not merely stale —
lib/src/lib.rs:1006-1010resolved topub enum RequiredEventswith the real targets ~220 lines away, andlib/src/https.rs:650-655resolved to anArc::new(snapshot)block with the real write-up 367 lines away. All are now symbol citations:Readiness::arm_writable/Readiness::signal_pending_write,HttpsSession::close, andConnectionH1::readable's close-delimited EOF branch.Scope
Every
*.rsin the tree, not a directory list — the defect is a property of the form, not of the citing directory, and a directory list would leavesim/,fuzz/,lib/benches, integration tests and everybuild.rsfree to reintroduce it. That it is not narrowed to nothing is proven rather than asserted: restricting it turns--self-testred on four separate assertions.Historical in-comment anchors follow
NOT_A_TEST's existing precedent — a table keyed on (citing file, exact citation text) with a stated reason — rather than a new mechanism, and an entry without a reason is documented as an unreviewed silencing.doc/**and**/LIFECYCLE.mdremain free to carry line numbers deliberately: there, a line number is sometimes the only way to point at a span with no symbol. Auditing those is #1466's remaining ask, which is tracked separately and is not closed by this.