Repository navigation
fix(facts): refuse cfg-gated doc examples for doctest registration (#8639) - #12029
Conversation
…8639) Doc examples separated from their item by cfg or cfg_attr gates, or in files with an inner #![cfg(..)] attribute, no longer register as tests. #[cfg(doctest)] remains admitted; split-doc detection no longer treats that attribute as doc metadata. Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 55 minutes. View limit details
|
EffortlessSteven
left a comment
There was a problem hiding this comment.
Review disposition: REVIEW_READY (author self-review, COMMENT)
Inspected: full diff on 2be4842f93; item_after cfg refusal; register_doctests inner #![cfg] skip; attribute_bears_doc_metadata fix for #[cfg(doctest)] split-doc false positive; module doc; 17 in-module tests including cfg refusal controls and #[inline]/#[must_use] preservation via existing html_blocks test.
Oracle: tests fail on main behavior for #[cfg(feature)], #[cfg(not(doctest))], #[cfg_attr], and #![cfg] files; pass after change.
Residual: no feature/target resolution (intentional fail-closed); does not close #8639 siblings.
|
Merge-ready handoff (frozen head)
|
EffortlessSteven
left a comment
There was a problem hiding this comment.
Independent review (fresh-context reviewer, head 2be4842): REPAIR_REQUIRED
Inspected:
- Head
2be4842f93e648b3556ec5dfe6d8b6a86e829857, basemain(a69bf0214f7bd7e0537a1cdd07e95608e5a366e8at the time the branch was cut), non-draft. Own contribution against the merge base:changelog.d/8639-doctest-cfg-gated.md,crates/ripr/src/analysis/facts/doctests.rs(+154/-8) andcrates/ripr/src/analysis/facts/doctests/tests.rs(+33). Nothing else. - The new refusal path, read at the reviewed SHA:
crates/ripr/src/analysis/facts/doctests.rs:332file_has_inner_cfg_gaterefuses a whole file carrying an inner#![cfg(..)]gate, called atdoctests.rs:97;doctests.rs:309item_afternow returnsNonewhenbetween_doc_and_item_cfg_refuses(doctests.rs:350) rejects the intervening attribute;doctests.rs:374attribute_cfg_familyclassifiescfg/cfg_attr/ other;doctests.rs:386attribute_is_cfg_doctestadmits only#[cfg(doctest)];doctests.rs:397attribute_path_and_optional_argsanddoctests.rs:424attribute_bracket_bodyare the new hand-rolled attribute parsers. - The doc-metadata rule that this PR also tightens: the previous
attribute_bears_doc_metadatamatched any attribute whose text merely contained the substringdoc, which is why#[cfg(doctest)]was misread as doc metadata. The new testcrates/ripr/src/analysis/facts/doctests/tests.rs:410(cfg_doctest_attribute_is_allowed_between_doc_and_item) pins the corrected behavior, anddoctests/tests.rs:390(cfg_gated_items_and_inner_cfg_files_register_nothing) pins the refusal. - The governing contract, read at the reviewed SHA:
docs/specs/RIPR-SPEC-0279-rust-doc-examples-as-tests.md. Its Non-Goals section at lines 197-200 states that "Feature, platform orcfg(not(doctest))gating of the documented function: like an ordinary#[test], an example on a gated function REGISTERS without establishing that defaultcargo testenables the gate." Its registration-rule list at lines 86-100 enumerates which items and which intervening attributes register, and line 94-96 names only doc-mentioning attributes (#[doc = ..],#[cfg_attr(.., doc = ..)],#[doc(hidden)]) as blocking.
Blocking:
- The published contract states the opposite of what this PR ships. RIPR-SPEC-0279:197-200 lists cfg-gated doctest registration as an explicit non-goal with the precise behavior "an example on a gated function registers"; this PR makes that example register nothing at all. The PR's own diff does not touch
docs/specs/, so the spec now asserts a rule the implementation deliberately inverts. Under the repository's own rule that a change updates the affected spec in the same commit, this is blocking: RIPR-SPEC-0279's Behavior section and its Non-Goals bullet must be rewritten to state that a gated item registers nothing, and that the refusal is by design rather than an open question. - The same spec's rule list (lines 86-100) is now incomplete in the other direction. The implementation refuses EVERY
#[cfg_attr(..)]and every#[cfg(..)]other than#[cfg(doctest)]between the comment and the item, but the spec only describes doc-mentioning attributes as blocking. A reader of the spec cannot tell that#[cfg_attr(feature = "x", doc = "extra")]now blocks registration for a cfg reason rather than a doc reason, nor that#[cfg(doctest)]is the single admitted exception. The rule list and the non-goals bullet have to move together.
Non-blocking:
attribute_bracket_body(doctests.rs:424) andattribute_path_and_optional_args(doctests.rs:397) count brackets and parentheses without skipping string literals, so an attribute whose argument contains a bracket inside a string, e.g.#[cfg_attr(feature = "a]b", doc = "x")], skews the depth counter and is not recognized as the cfg family. The attribute then does not refuse, so an example under it can still register. This is the permissive direction on a rule whose whole point is to refuse, so a string-aware scanner would be the safer construction even though the current miss is narrow.attribute_is_cfg_doctestcollapses whitespace before matching (doctests.rs:386), so#[cfg(doctest)]is admitted while#[cfg(all(doctest, unix))]is refused. Refusing the compound form is conservative and defensible, but it means the single admitted exception is narrower than "cfg(doctest)" reads in the spec text.- The change is fail-closed in the direction that matters: a shape it cannot resolve becomes a refusal rather than a credited test, so the worst outcome is a withheld finding, not a false gap.
Efficiency/performance:
- No regression found, and the new ordering is marginally cheaper than what it replaced.
file_has_inner_cfg_gate(doctests.rs:332) is inserted atdoctests.rs:97BEFORE the existing "Most files hold no fenced example" early-out, but it only reads the file header andbreaks at the first line that is neither blank, a//comment, nor#-prefixed, so it is O(header) per file and cheaper than the full-file fence scan it now precedes. The per-attribute parsers are O(attribute length) and run only for attributes that already sit between a doc comment and an item. No superlinear behavior, no per-file re-scan, and no new allocation on the hot path was found.
Not run:
- Hosted exact-head Rust proof is unavailable for this head: the required check
Ripr Rust Small Resultis ABSENT from this head's check set and every Rust context reportsSKIPPED(20 skipped, 9 success, 1 cancelled, 1 neutral). The only non-success check isub-review, CANCELLED, which is why the rollup reads FAILURE; it is a cancelled provider, not a code failure. No Rust verdict exists for2be4842f. cargo test -p ripr --lib analysis::facts::doctestswas not run locally; the two new unit tests atdoctests/tests.rs:390anddoctests/tests.rs:410were read, not executed.cargo xtask precommit,cargo xtask fixturesandcargo xtask goldens checkwere not run, and no workspace build was performed.- The fixture/golden consequence of the new refusal was not measured: if any committed fixture or verdict-corpus row relies on a cfg-gated doctest registering, only
cargo xtask fixturesandcargo xtask goldens checkwould show it, and neither was run here. - What WAS verified locally and read-only: the source text and git blob identity of
doctests.rsanddoctests/tests.rsat the reviewed SHA, the spec text at lines 86-100 and 186-200 at the same SHA, the PR's file list against the merge base, and the GitHub check-run set. No repository file was modified and HEAD was not moved.
Reviewed by an independent Mavis review agent on behalf of the maintainer; bound to head 2be4842f93e648b3556ec5dfe6d8b6a86e829857. Not an approval.
Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com>
|
Restacked on current main (includes #12030). Frozen head for qualification: |
There was a problem hiding this comment.
Reporter summary
All substantive lanes confirm one unresolved correctness regression: file_has_inner_cfg_gate treats inner #![cfg_attr(...)] as a file-wide gate via attribute_is_cfg_family, suppressing unrelated doctests even though the stated scope only covers inner #![cfg(...)]. This conflicts with the PR body, module docs, changelog, and the existing Graphite review comment; the smallest fix is to restrict this check to AttributeCfgFamily::Cfg and add a regression test showing that inner #![cfg_attr(docsrs, feature(doc_cfg))] does not suppress doctests while inner #![cfg(feature = "x")] and item-level cfg gates still do. The reported 17-test result is not independently corroborated because the routed cargo-test receipt timed out, so the current test evidence does not cover this control.
…comment placement (#8639) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG
There was a problem hiding this comment.
Decision
- Needs verification checks before upstream.
Verification questions
- Confirm the changelog says cfg-gated examples register unless the only cfg between comment and item is cfg(doctest); item-level cfg_attr remains refused while crate-level cfg_attr does not gate the file.
- Confirm the cfg(doctest) exception is tested at the parser and doc_examples levels, but not through the full doctest registration path.
- Confirm the changed diff provides focused coverage for the principal cfg variants but does not establish exhaustive sibling-path coverage for other attribute spellings or parsing routes.
Parked follow-ups
- The change intentionally fails closed for cfg predicates without resolving features or targets, but that boundary may affect users relying on conditional doctest registration.
Evidence gaps
- The routed cargo-test receipt is absent, leaving the reported 17-test result uncorroborated in this review packet.
- Model proof intent was rejected by deterministic validation.
- The configured ripr sensor failed and the cargo-test receipt is absent in the supplied packet, so the reported 17 passing tests are not independently corroborated here.
- Focused test proof is not independently available: the PR body claims 17 passing tests, but the scheduled cargo-test receipt is absent and ripr failed with exit code 2.
…gated doctest refusal (#8639, #12230) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG
…cfg) gates the file, spec and traceability for cfg refusal (#8639) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmoz3yvGnngtDNnPKxG
|
Review of record, head Inspected, from the full diff and the semantic owner (
Hosted proof: Generated by Claude Code |
…eature (#12230) Resolve cfg(feature = "..") against the package's default feature closure so rust-hex-style alloc/std gated doctests register again; negations, non-default features, target and custom cfg values, and cfg_attr still refuse (#8639). Restores the pilot-ranking pick dropped by #12029 (#12262). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmpsNgQecNbZm8AXS3m
…eature (#12230) Resolve cfg(feature = "..") against the package's default feature closure so rust-hex-style alloc/std gated doctests register again; negations, non-default features, target and custom cfg values, and cfg_attr still refuse (#8639). Restores the pilot-ranking pick dropped by #12029 (#12262). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmpsNgQecNbZm8AXS3m
…eature (#12230) Resolve cfg(feature = "..") against the package's default feature closure so rust-hex-style alloc/std gated doctests register again; negations, non-default features, target and custom cfg values, and cfg_attr still refuse (#8639). Restores the pilot-ranking pick dropped by #12029 (#12262). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmpsNgQecNbZm8AXS3m
…12230) #12029 refuses any cfg-gated doc example. That dropped the rust-hex encode_upper doctest (its only direct_owner_call test; items under cfg(feature = "alloc")), moving its seam weakly_gripped to activation_unknown and the pilot pick pooled 39 to 38 (#12262). Resolve plain cfg(..) item and file gates against the owning manifest's default-enabled features (shared expand_default_features rule with #7266): test off, doctest on at the item gate and off at the file gate, feature = "x" by default membership. Target, custom and unknown predicates, cfg_attr, malformed predicates and head shapes, and gates without an establishing manifest still refuse. Restores the hex-from-hex-odd-variant credit and deletes its missed-credit ledger entry as that entry instructs.
…eature (#12230) (#12368) * fix(facts): credit a doctest on an item gated by a default-on cargo feature (#12230) Resolve cfg(feature = "..") against the package's default feature closure so rust-hex-style alloc/std gated doctests register again; negations, non-default features, target and custom cfg values, and cfg_attr still refuse (#8639). Restores the pilot-ranking pick dropped by #12029 (#12262). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmpsNgQecNbZm8AXS3m * fix(facts): default-feature walk terminates when a feature list names default (#12230) Separate the visited set from the credited feature names so default = ["default"] and cycles through default end; add direct and through-default controls. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmpsNgQecNbZm8AXS3m * fix(facts): credit an undeclared default feature only as an optional dependency's implicit feature; bump cache generations (#12230) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmpsNgQecNbZm8AXS3m * fix(facts): read default features from committed manifest overlay (#12230, #12368) Rebase onto main kept 1.137/0.139 cache generations after #12266 landed 1.136/0.138. Restore analyzed_manifest so feature gates follow analyzed sources, add overlay regression test, and re-chain unchanged-after-attempt fixture hashes. Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com> * fix(app): pass package_root to rust_test_stub in local seam helper Main added a package_root parameter to rust_test_stub; the local expression helper still used the old arity and blocked compilation during rebase precommit. Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com> * chore(goldens): re-bless owner_return_pin JSON fixtures after #10162 main merge Precommit goldens check (triggered by #12230 verdict-corpus delta) found stale expectations on rebased main. Re-bless with RIPR-SPEC-0240 rationale. Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com> * fix(cache): pin the 1.138 cache generation in docs, currentness constants and the chained fixtures; restore the overlay-manifest traceability entry (#12230) The main merge took cache 1.137 for #10162, so this change moves to 1.138 / 0.140. The unchanged-after-attempt fixtures are regenerated from ripr check output at 1.138 and their receipt chain re-computed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmpsNgQecNbZm8AXS3m * fix: restore main's owner_return_pin goldens and align test_stub with the main-break fix (#12230) The re-bless turned 18 owner_return_pin_json_* golden files into static_unknown while the binary at that head still emits main's values; restore main's expected files. Take rust_test_stub's package_root as in #12466 (Some(root)) so the cfg-gated parent check applies and this branch merges cleanly with that fix. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmpsNgQecNbZm8AXS3m * fix(facts): credit a declared default feature and a plain name/feature dependency enable (#12230) A declared `default` feature is enabled in a plain cargo test, and a plain `name/feature` entry in the default closure enables the optional dependency `name`, so its implicit feature is on. Both only add credit where Cargo enables the feature; `dep:name` and the weak `name?/feature` still add nothing. RIPR-SPEC-0279 states the rule and the negative controls pin it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmpsNgQecNbZm8AXS3m * fix(facts): credit a doctest on an item gated by a default-on cargo feature (#12230) Resolve cfg(feature = "..") against the package's default feature closure so rust-hex-style alloc/std gated doctests register again; negations, non-default features, target and custom cfg values, and cfg_attr still refuse (#8639). Restores the pilot-ranking pick dropped by #12029 (#12262). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmpsNgQecNbZm8AXS3m * fix(facts): default-feature walk terminates when a feature list names default (#12230) Separate the visited set from the credited feature names so default = ["default"] and cycles through default end; add direct and through-default controls. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmpsNgQecNbZm8AXS3m * fix(facts): credit an undeclared default feature only as an optional dependency's implicit feature; bump cache generations (#12230) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmpsNgQecNbZm8AXS3m * fix(facts): read default features from committed manifest overlay (#12230, #12368) Rebase onto main kept 1.137/0.139 cache generations after #12266 landed 1.136/0.138. Restore analyzed_manifest so feature gates follow analyzed sources, add overlay regression test, and re-chain unchanged-after-attempt fixture hashes. Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com> * chore(goldens): re-bless owner_return_pin JSON fixtures after #10162 main merge Precommit goldens check (triggered by #12230 verdict-corpus delta) found stale expectations on rebased main. Re-bless with RIPR-SPEC-0240 rationale. Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com> * fix: restore main's owner_return_pin goldens and align test_stub with the main-break fix (#12230) The re-bless turned 18 owner_return_pin_json_* golden files into static_unknown while the binary at that head still emits main's values; restore main's expected files. Take rust_test_stub's package_root as in #12466 (Some(root)) so the cfg-gated parent check applies and this branch merges cleanly with that fix. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmpsNgQecNbZm8AXS3m * fix(facts): credit a declared default feature and a plain name/feature dependency enable (#12230) A declared `default` feature is enabled in a plain cargo test, and a plain `name/feature` entry in the default closure enables the optional dependency `name`, so its implicit feature is on. Both only add credit where Cargo enables the feature; `dep:name` and the weak `name?/feature` still add nothing. RIPR-SPEC-0279 states the rule and the negative controls pin it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmpsNgQecNbZm8AXS3m * fix(cache): bump default-feature doctest cache to 1.139 / 0.141 on rebased main Re-chained unchanged-after-attempt fixtures and aligned currentness docs after rebasing onto main (#12359 at 1.138). Restores overlay-manifest traceability for RIPR-SPEC-0279 (#12230). Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com> * fix(fixtures): recompute the content commitment of the two honesty-corpus reports bumped to 1.139 (#12230) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvmPmpsNgQecNbZm8AXS3m --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com>
…ed 39 picks #12337 re-baselined the ranking lane to the mid-regression 38-pick score while #12029's cfg-gated doctest refusal still suppressed one rust-hex pick; #12368 restored that pick and the hosted score returned to 39 picks (dispatch 41526672019, nightly 41590770053, dispatch 41651247855). The checked-in floor has been one pick below the restored normal since Nov 2, so a repeat of that exact regression would pass the gate. Record the restored normal from hosted run 41651247855 (main ac01337, github-hosted-linux-x86_64-4cpu platinum-8370c, pinned 1.95.0, corpus 2026-10-04.1): ranking metric values, sample details, revision and runner_class only; targets and margins untouched. Same minimal-patch method as #11054 and #12337. Proof: dx-scoreboard --boards ranking --ingest <hosted score> --baseline <new baseline> --gate exits 0 with all 9 ranking rows comparable and no regressions; PUBLIC_PROOF.md re-rendered and its receipts-table test pin updated; cargo fmt --check, clippy -p xtask --all-targets -- -D warnings, receipts_table_names_lane_revisions and committed_baseline_carries_every_ranking_metric_completed all green under the WSL Ubuntu pinned toolchain.
…ed 39 picks (#12818) Record the restored hosted normal (39 picks, 7 confirmed / 18 refuted, 28 distinct; corpus 2026-10-04.1) from run 41651247855 at main ac01337: #12337 had re-baselined to the mid-regression 38-pick score while #12029's doctest refusal still suppressed one pick, and #12368 restored it. Values, sample details, revision and runner_class only; targets and margins untouched. Same method as #11054/#12337. Proof: hosted Pilot Ranking run 41673003404 on this head passes score + baseline compare; local WSL gate replay exits 0 with all 9 rows comparable; required Ripr Rust Small Result green; advisory drift lane red only on the pre-existing 818-vs-840 corpus receipt lag that fails identically on main.
Summary
Doc examples on items separated from their comment by
#[cfg(..)]or#[cfg_attr(..)], or in files gated by#![cfg(..)], no longer register as mined tests.#[cfg(doctest)]remains admitted (rustdoc enables it when running doctests). Split-document detection no longer treats#[cfg(doctest)]as doc metadata because of a substring false match.Swarm / Source Boundary
ripr-swarmGoverning issue or accepted claim: #8639
Advances #8639
Acceptance delta (one sentence): Item 2 of #8639 — cfg-gated doc examples and inner
#![cfg(..)]files fail closed instead of registering doctestTestFacts that rustdoc may not run.Scope
crates/ripr/src/analysis/facts/doctests.rs,doctests/tests.rs,changelog.d/8639-doctest-cfg-gated.mdProof
cargo test -p ripr --lib analysis::facts::doctests cargo xtask precommitcargo test -p ripr --lib analysis::facts::doctests: 17 passed.cargo xtask precommit: fails at inheritedcheck-process-policyon main (crates/ripr/src/output/first_pr/run_chain.rsorphaned allowlist entry); not introduced by this diff. All change-scoped checks through that point passed, includingcheck-changelog-fragments.Claim boundary
Establishes static refusal of cfg-gated doctest registration without resolving Cargo features or targets. Does not close #8639 (remaining items: should_panic, block docs, module visibility, display names, etc.).