Skip to content

[WIP] @bobhy's Extern crates in doc tests#3137

Open
pczarn wants to merge 39 commits into
rust-lang:masterfrom
pczarn:extern_crate
Open

[WIP] @bobhy's Extern crates in doc tests#3137
pczarn wants to merge 39 commits into
rust-lang:masterfrom
pczarn:extern_crate

Conversation

@pczarn

@pczarn pczarn commented Jun 16, 2026

Copy link
Copy Markdown

Allows doc tests to freely reference external crates in use statements.
Avoids depending on unstable Cargo interfaces to determine dependencies by the
simple expedient of running a cargo build --verbose and observing how Cargo invoked the compiler.
Includes necessary doc changes.

Fixes #706 and #394.
Does not address #768.

bobhy added 30 commits December 9, 2024 12:40
Also refactor the `mdBook test` section and add a new "writing doc tests" chapter.
… project: changed config rust.package-dir to rust.manifest
and preferring [rust.manifest] over [rust.edition].
make chap Alternate Backends pass doctest.
Prefer edition setting from Cargo.toml over book.toml; sadly, Cargo also overrides command line.
@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Jun 16, 2026
@pczarn pczarn marked this pull request as draft June 16, 2026 10:44
@rustbot rustbot removed the S-waiting-on-review Status: waiting on a review label Jun 16, 2026
@pczarn

pczarn commented Jun 16, 2026

Copy link
Copy Markdown
Author

Original @bobhy 's code in #2503.

@pczarn pczarn marked this pull request as ready for review June 20, 2026 12:34
@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Jun 20, 2026
@pczarn

pczarn commented Jun 20, 2026

Copy link
Copy Markdown
Author

@ehuss Would you take a look to see whether this is a valid design? The PR used to be hacky, and it still remains hacky, hopefully less so.

@pczarn

pczarn commented Jun 21, 2026

Copy link
Copy Markdown
Author

@ehuss

Alternative design

  • create a temporary directory
  • put Cargo manifest into that directory
  • use cargo locate-project --workspace and CARGO_WORKSPACE_DIR=path to use the original workspace for the temporary project
  • generate code either as integration tests or as doc tests on modules (?)
  • test the temporary project with cargo test [--doc] --target-dir=path/to/target

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: waiting on a review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to reference 3rd-party crates

3 participants