should_panic in doctests accepts crashes, aborts, std::process::exit
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
/// ```should_panic
/// std::process::exit(1);
/// ```
fn f() {}
cargo test
I expected to see this happen: test fails.
Instead, this happened: test passes.
This also applies to explicit aborts, the process being killed by a signal, Miri aborting execution due to UB, etc. I've just found UB in my doctest that was accidentally hidden by this, and I only stumbled upon it because
WARNING: No rustdoc doctest environment variable provided so doctests will be run in the same process
happened when running under cross and apparently that affects how should_panic works.
This applies to both separate doctest binaries and edition 2024-style merged doctests.
Meta
rustc --version --verbose:
rustc 1.90.0-nightly (28f1c8079 2025-06-24)
binary: rustc
commit-hash: 28f1c807911c63f08d98e7b468cfcf15a441e34b
commit-date: 2025-06-24
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7
@rustbot label +A-doctests +T-rustdoc
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the reproducer in the issue as the entry point: run cargo test with the should_panic doctest containing std::process::exit(1), then compare the separate and merged doctest cases described in the report. Trace rustdoc's doctest handling; done means crashes, aborts, signals, and Miri UB are not accepted as should_panic successes while ordinary panics retain the expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100