Repository navigation
Open
Labels
A-CLIArea: Command-line interface (CLI) to the compilerA-doctestsArea: Documentation tests, run by rustdocB-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-needs-to-bakeStatus: The implementation is "complete" but it needs time to bake.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
Description
A command line option to pass program arguments to the underlying compiler building doctests.
Original issue motivating this feature: #67533.
Note
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports.
Instead, open a dedicated issue for the specific matter or post in the #t-rustdoc Zulip channel.
Discussion comments will get marked as off-topic or deleted.
Repeated discussions on the tracking issue may lead to the tracking issue getting locked.
Steps
- Implementation PR
- Stabilization PR
Unresolved Questions
- Should argument parsing be closer to what already exists for RUSTFLAGS (whitespace splitting and nothing else) or should it be closer to how shell parses input (take into account escaped characters and quote characters)? Or should we offer two options, one that works like RUSTFLAGS for human users and one that works like CARGO_ENCODED_RUSTLFAGS for tool usage? Update: #137096 (comment) changed the requirements and #139863 the design!
- From #139863: Even though we don't process the argument passed to
--doctest-build-arg, we end up passing it via an argument file (rustc @argfile) which delimits arguments by line break (LF or CRLF, via) meaning ultimately the arguments still get split which is unfortunate. Is there are good way to resolve this (obvious but intrusive solution: smh signal torustcnot to split inside the argsfile)?
Implementation History
Metadata
Metadata
Assignees
Labels
A-CLIArea: Command-line interface (CLI) to the compilerA-doctestsArea: Documentation tests, run by rustdocB-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-needs-to-bakeStatus: The implementation is "complete" but it needs time to bake.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
Type
Projects
- StatusShow more project fieldsNo status
Activity
Rollup merge of rust-lang#128780 - GuillaumeGomez:rustflags-doctests,…
Unrolled build for rust-lang#128780
weihanglo commentedon Dec 21, 2024
Considering all linked issues (#67533, #66623, rust-lang/cargo#13697, rust-lang/miri#3869) are actually Cargo-related, I wonder how to integrate this flag to help Cargo users. Cargo doesn't parse
RUSTFLAGSso it may not know if--cap-lints=warnis there and pass to--doctest-compilation-argsaccordingly.Also, the feature seems to open a door way bigger than what #67533 was looking for. It accepts arbitrary rustc flags. Mind sharing why propagating
-cap-lintsisn't under consideration? Maybe there are other use cases for arbitrary flags I am missing. We all know that once we provide more stuff to users, we might have no chance to take it back 😓.That said, I don't think this feature on its own is bad. Thank you for working on a fix!!
Rollup merge of rust-lang#139863 - fmease:simp-doctest-build-arg-pass…
Rollup merge of rust-lang#139863 - fmease:simp-doctest-build-arg-pass…
Rollup merge of rust-lang#139863 - fmease:simp-doctest-build-arg-pass…
Unrolled build for rust-lang#139863
[-]Tracking Issue for rustdoc `--doctest-compilation-args` command line option[/-][+]Tracking Issue for rustdoc `--doctest-build-arg` command line option[/+]Rollup merge of rust-lang#147013 - fmease:fix-docs-doctest-build-arg,…
Unrolled build for #147013
Rollup merge of #147013 - fmease:fix-docs-doctest-build-arg, r=Guilla…
josephlr commentedon Sep 29, 2025
I can offer some context on why this feature might be useful if properly integrated into
cargo. Ingetrandom's tests, we want to run our existing tests with the unstable-Zsanitizer=memoryflag.If we replace instances of:
cargo test --target=x86_64-unknown-linux-gnuwith
our building, linking, and testing work exactly as expected, except for doctests.
For doctests, as far as I can tell, it's not currently possible to pass
-Zsanitizer=memoryin all the necessary locations to make doctests work. Specifically, even the following does not work (on the currently nightly):giving the following error:
While we can just disable doctests when testing with the sanitizer, I think this provides a good example for making sure the correct build flags are passed everywhere.
It often seems like when doing anything complicated with
RUSTFLAGSor testing in general, the answer is "just don't use doctests". However, I really like doctests, and would like to see them well integrated with the rest of the Rust testing story.In an ideal world, setting
RUSTFLAGSshould work for all build invocations, including those for doctests, andRUSTDOCFLAGS/--doctest-build-argwouldn't even be necessary. However, I understand that doing this in a backwards-compatible way might be challenging.[-]Tracking Issue for rustdoc `--doctest-build-arg` command line option[/-][+]rustdoc: Tracking issue for command-line option `--doctest-build-arg`[/+]fmease commentedon Nov 14, 2025
Thanks for your report. However, I'd like to draw attention to the prominent banner in the issue description, most notably this part:
Moreover, it's unclear how your issue relates to the experimental command-line option
--doctest-build-argwhich this issue is tracking, I see no mention of it in your report.Regarding your following statement:
You are mixing up two different concepts, namely the build system Cargo and the programs rustdoc / rustc. rustdoc doesn't know anything about
RUSTDOCFLAGSorRUSTFLAGSand rustc doesn't know anything aboutRUSTFLAGS, these environment variables are only read & understood by Cargo.It might indeed lead to library unsoundness (not language unsoundness) if the assumptions made by the library author turn out to be false (either due to a Cargo or rustdoc bug or due to misconceptions of the author).
It would be great if you could create a separate issue with a minimal reproducer so it's easier for us to see what might be going on. https://github.com/rust-lang/rust/issues is fine, I'll transfer to https://github.com/rust-lang/cargo/issues if needed, once I can visualize the problem since right now I can only speculate that some flags might not get forwarded from rustdoc to the rustc used for compiling doctests or that inlined cross-crate re-exports could play a role here (where rustdoc inlines items defined in a crate that was compiled with rustc instead of rustdoc).
valadaptive commentedon Nov 14, 2025
I've removed the original comment. I don't think it needs much discussion and is probably intended behavior, albeit confusing. I think opening an issue would get it closed as a duplicate of this one, so I'll just wait for the broader "passing RUSTFLAGS into rustdoc" problem (is there a tracking issue for that?) to be solved.
The closest thing I found on Google relating to my issue was https://internals.rust-lang.org/t/can-we-do-something-about-rustflags-rustdocflags/21513, which referenced #67533. That issue was closed by #128780, which is being tracked in this issue. That led me to assume #67533 is "fixed" and you won't accept any more discussion on that issue, so I couldn't really find an ideal place to bring it up.
After thinking things over, I think I was "reporting" a known issue, albeit in a roundabout way, and we're just waiting on someone to resolve the open questions and stabilize things. Apologies for wasting your time.
Rollup merge of #147013 - fmease:fix-docs-doctest-build-arg, r=Guilla…
Rollup merge of #147013 - fmease:fix-docs-doctest-build-arg, r=Guilla…