rustdoc: Emit a lint warning if doctest contains `#[test]` functions but isn't marked `test_harness`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
/// ```
/// #[test]
/// fn my_test() {
/// panic!("this test should fail");
/// }
/// ```
const _: () = ();
I expected to see this happen: running cargo test would try to run my_test and report it failed.
Instead, this happened: it reports the doctest ran successfully.
I want to be able to use #[test] in a doctest to document things that are intended to only be used inside a #[test] (since they print errors to stdout/stderr and/or panic for better testing ergonomics, instead of returning a Result).
Meta
I tried it on 1.96.0 stable as well as 1.98.0-nightly (2026-06-03 b354133fb126352871be)
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
Reproduce the linked doctest with cargo test and begin at rustdoc's doctest handling and diagnostic entry points. Trace how #[test] functions are treated when test_harness is absent; done means this case emits a lint warning and coverage verifies the expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100