Skip to content

fix(rust): scan doctest code in doc comments for inputs - #230

Merged
adityankale190895 merged 3 commits into
DiffCI:mainfrom
FredApps:rust/doctest-inputs
Nov 18, 2026
Merged

adityankale190895 merged 3 commits into
DiffCI:mainfrom
FredApps:rust/doctest-inputs

Conversation

@FredApps

@FredApps FredApps commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #222

Doc comments (///, //!, /** */, /*! */) are now scanned for code that rustdoc runs as doctests, and that code goes through the same input scan as ordinary code. A doctest that include_str!s or reads another crate's file now becomes an edge or a fallback, exactly as it would in a #[test].

  • docComments finds doc comments while skipping strings, character literals and plain comments, so a "/**" glob isn't mistaken for one.
  • doctestCode keeps fenced blocks that rustdoc treats as Rust: no language, rust, or only doctest attributes. It also keeps indented blocks, and removes the hidden-line # prefix.
  • rustSourceInputs merges both scans. In analyzeRustMetadata, only the one call site changes.

The new test covers line, inner and block doc comments, an indented block, an include_str! and a computed include! in doctests. It also checks that prose, text/toml blocks and plain // comments name no inputs.

Effect on real code: I ran it over 56,314 .rs files from 1,815 registry crates. 11 files newly fall back, most of them for real reasons (computed includes in doctests). Three are typed-path's br"\" doctests, which #220 fixes. Scanning is still linear: about 300 ms for a 2 MB file, end to end.

Validation (Linux, Node 22, Cargo 1.100): npm run typecheck and the Rust test files (tests/repo/rust-*.test.ts, tests/planner/rust-command.test.ts) pass. The new test fails on main and passes here.

Hidden conflict with #250 / #258 (fixed here): #250 adds a runsPrograms flag to rustInputs. The old rustSourceInputs listed its flags by name, so merging #250 after this PR would have failed typecheck with no textual conflict. rustSourceInputs now ORs every boolean flag of the code and doctest scans by key, so the two merge in either order. Checked: typecheck and the Rust tests pass on this branch alone and merged with #258.

@FredApps
FredApps marked this pull request as ready for review November 17, 2026 17:18
I, FredApps <[email protected]>, hereby add my Signed-off-by to this commit: 4c0e634

Signed-off-by: FredApps <[email protected]>
…xed list

rustSourceInputs listed the flags it ORs. DiffCI#250 (also in DiffCI#258) adds runsPrograms to rustInputs; merged after this PR, the doctests' value would have been dropped and typecheck would fail, with no textual conflict to warn about. Combining the flags by key keeps both PRs correct in either order.

Signed-off-by: FredApps <[email protected]>
@adityankale190895
adityankale190895 merged commit 6670d2c into DiffCI:main Nov 18, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust adapter: doctest code is never scanned for includes or paths

2 participants