# Inject doctests into host crate
Idea by @Urgau.
Tracking issue: [#141083](https://github.com/rust-lang/rust/issues/141083).
## 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 ...)
## 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
- 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?
- 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