Open
Description
From: https://hackmd.io/@fmease/inject-doctests-into-host-crate:
Motivation
- Have doctest work in binary crate
- Have better warnings and errors reporting by having correct spans
- Handle doctests with different editions in the same compilation unit
- Simplify cross-compilation (deprecating all the --doctest-cross-arg ...)
- Better Cargo integration (parallel test exec, smarter
unused_crate_dependencies
, ...)
Implementation
- Have a hook in the AST->HIR lowering that is only implemented by rustdoc:
- It would parse the doctests, create the AST nodes (by calling rustc_parse maybe?) and give back to rustc the AST nodes corresponding to
#[test] fn doctest_1234 { ... }
with the doctest body inside
- It would parse the doctests, create the AST nodes (by calling rustc_parse maybe?) and give back to rustc the AST nodes corresponding to
- Rustdoc would give spans corresponding to the original doctest code in the doc comment. This could include a different edition for doctests that override that
- Problem: how would we get the spans to be correct given the presence of
///
in the original code but not the new code given to rustc_parse? would it just work or does it need more invasive changes?
- Problem: how would we get the spans to be correct given the presence of
- These AST nodes would then be injected into the crate and lowered into HIR and go through the rest of the compilation
- Then we run them using the libtest harness.
- We need to run all rustc passes to make it work
Implementation History
Empty.
Metadata
Metadata
Assignees
Labels
Area: Documentation tests, run by rustdocCategory: An issue tracking the progress of sth. like the implementation of an RFCStatus: The feature has not been implemented.Relevant to the compiler team, which will review and decide on the PR/issue.Relevant to the rustdoc team, which will review and decide on the PR/issue.
Type
Projects
Status
No status