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
Rust adapter: doctest code is never scanned for includes or paths #222
The input scan skips every comment, including doc comments. But rustdoc compiles and runs the code blocks in ///, //!, /** */ and /*! */ comments as doctests, and cargo test runs them from the crate directory. So an include_str!, a computed include! or a literal path in a doctest is never seen.
Repro (I checked it with real Cargo). In a workspace with crates/a and crates/b, crates/a/src/lib.rs has:
/// Every crate keeps its licence header.////// ```/// let b = include_str!("../../b/src/lib.rs");/// assert!(b.starts_with("// SPDX"), "b lost its header");/// ```pubfndocumented(){}
cargo test -p a --doc passes, and fails as soon as crates/b/src/lib.rs loses its header. DiffCI reports no blocker and no a → b edge, so a change to b alone would skip a's doctest. The same thing happens with std::fs::read_to_string("../b/src/lib.rs") inside a doctest. That is the same read that already becomes an edge when it's in ordinary code.
Fix: pull out the code of each doc-comment block that rustdoc treats as Rust: fenced blocks with no language, rust, or only doctest attributes (no_run, should_panic, ignore, compile_fail, editionNNNN, …), and indented blocks. Remove the hidden-line # prefix, then run the same scan over that code. Prose, text/toml/sh blocks and plain // comments stay ignored.
I measured it on the 56,314 .rs files under a local ~/.cargo/registry (1,815 crates). 11 files newly fall back. Five of them really do use computed includes in doctests (pkcs1, tiff, built ×2, gl_generator), and three are the br"\" bug from #220 (typed-path). Another 708 files gain literal paths.
Activity